0

I have a module "Module1" and I can execute with the command below (in the project folder):

  • $ mvn appengine: run

Now I have another module "Module2", which I can also execute with the same previous command.

I need to run both modules at the same time. How can I do this?

Thiago
  • 21
  • 4

1 Answers1

2

From your usage of the Goal appengine:run I understand that you are testing your application with the Local Development Server. By having a look at the documentation for appengine:run, you can use the flag port to launch two independent instances of the Development Server in different ports.

You can define that flag by using a command like:

mvn appengine:run -Dapp.devserver.port=<PORT_NUMBER>

The default port number in the Development Server is 8080, so you can, for example, use port 8080 for your Module1 and then use a different port, such as 8082 for your Module2. That way, you can move to the directories where your two services are located, and run those two commands with different port numbers, and then you will be able to access them in localhost:8080 and localhost:8082, respectively.


Update (possibly a better solution)

Actually, as stated in the documentation:

If the root directory of your project contains only your services, you can deploy all those services with a single Maven command.

This works both for a deployment in the production environment (App Engine) and also in the Development Server. So if you configure your application appropriately, you can launch both services in the same development server instance (they will still launch in different ports) using a single mvn appengine:run command.

So in order to configure a Java GAE application with all its services, you can follow the same idea presented in this (unrelated to this topic) migration guide. To do so, when you configure the com.google.cloud.tools » appengine-maven-plugin in the pom.xml file in your default service, you have to add the <services> tag, including all the services in your application, starting by the default service:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>appengine-maven-plugin</artifactId>
  <version>1.3.1</version>
  <configuration>
    <deploy.project>PROJECT_NAME</deploy.project>
    <deploy.version>PROJECT_VERSION</deploy.version>
    <services>
        <!-- Default service -->
        <service>    
          ${project.build.directory}/${project.name}-${project.version}
        </service>
        <!-- One for each additional service -->
        <service>
          ${project.parent.basedir}/SERVICE_NAME/target/SERVICE_ARTIFACT-${project.version}
        </service>
    </services>
  </configuration>
</plugin>

Once this is complete, your application will detect all the services associated to it, and you will be able to work with all of them simultaneously with a single Maven command, i.e. mvn appengine:deploy will deploy all services and mvn appengine:run will start a Development Server with all services in it. For the case of the Development Server, you can visit the Server Admin in localhost:PORT/_ah/admin, and then move to the Modules tab to find the URLs for each of the running services:

enter image description here

I hope one of these two alternatives (although I would go for the second) are useful for your use case.

dsesto
  • 7,864
  • 2
  • 33
  • 50
  • This might not work well if the modules rely on sharing the memcache or datastore as each development server process manages its own "copy" of such data and there could be inconsistencies between the copies. – Dan Cornilescu Feb 28 '18 at 19:09
  • @DanCornilescu you are right, that would be one of the limitations of the approach I suggested. I have just come across another solution that may be more convenient here too, so let me update my answer. – dsesto Mar 01 '18 at 10:11
  • have you got to use spring-cloud-starter-kubernetes-config ? to use secrets anc configmaps !!! once i tried i got this exception : WatchConnectionManager : Exec Failure: HTTP 403, Status: 403 - java.net.ProtocolException: Expected HTTP 101 response but was '403 Forbidden' repository : https://github.com/jamesmedice/Spring-Boot-GCP – Tiago Medici Oct 28 '19 at 19:52