lowselfesteemsucks
lowselfesteemsucks

Reputation: 855

Is Maven starting two different JVM's?

I have a project where with java backend (X), I need to start another maven project (Y) (something like mvn test). This works fine using ProcessBuilder.

I also added recently JMX configuration to monitor the Y-JVM, because there can be multiple Y-projects running. The JMX configuration is passed as env variable MAVEN_OPS and I have a method to generate unique random ports in range. I am also able to connect to JMX on the random generated port, from my X backend, but the problem is that this only works while the project is in building state. Right after build is done, and the maven should "start" the service, I got this error:

[INFO] --- gatling-maven-plugin:2.2.4:execute (test1) @ xxxxxxx -- Pruning sources from previous analysis, due to incompatible CompileSetup.

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 15.388 s

[INFO] Finished at: 2018-12-27T09:31:10+01:00

[INFO] Final Memory: 15M/363M

[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal io.gatling:gatling-maven-plugin:2.2.4:execute (test1) on project xxxxxxx: Xxxxxx failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1] [ERROR]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: xxxx; nested exception is: java.net.BindException: Address already in use (Bind failed)

Before this point I am able to get the metrics using JMX. So now, my question is, does maven use different JVM in build and execute state? Why my port is already in use???

Upvotes: 1

Views: 249

Answers (2)

Sofo Gial
Sofo Gial

Reputation: 703

Creating a unique range of ports on project Y, does not guarantee that a collision will not happen with a port used from project X. Instead of creating a range of ports in advance, you can create them dynamically at the moment you need to connect to them. Just make sure you catch any exceptions and retry with a different port. E.g. try to connect to 8080, if unsuccessful try 8081, then 8082 etc, until a connection is established.

Upvotes: 0

yogesh sharma
yogesh sharma

Reputation: 81

Each java program will execute in its own JVM, so answer to your question yes Maven will execute in it own JVM.

Elaborate more on back-end, is it spring boot or some other application. You may need to explicitly define port for each back-end. Do you require any help in Gatling context, as I see gatling logs in snippet.

Upvotes: 1

Related Questions