I have a project in Eclipse which, after assembly has a package structure of the following
launcher.tar.gz
|-- launcher.jar
|-- lib/
|-- resources/
|-- plugins/
Which is achieved using the maven-assembly-plugin
.
For the application to properly start, some of resources
are required, but not available outside of the final assembly, additionally, I would like to have the ability to install plugins as I currently do.
My current workflow is
$ mvn [clean] package
$ cd target/launcher/
$ java -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -jar launcher.jar
Once the application has launched in a suspended state, I can attach the debugger and resume my normal workflow.
How can I streamline this process from Eclipse?
I can launch this from my Launcher.java class, but when debugging in Eclipse, I do not have the ability to install plugins via this method.
Following the advice of Braheem, I was able to accomplish this using the exec-maven-plugin
plugin, however I changed up a bit to make it more platform independent.
Using the profile definitions from this answer, I can use ${script.extension}
to swap between .sh and .bat
I have the following plugin definition that I can execute using the verify
target, which will eventually become a custom target entirely.
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.5.0</version>
<executions>
<execution>
<id>Application Launcher</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>"${project.build.directory}\${project.artifactId}-${project.version}\bin\launcher${script.extension}"</executable>
<arguments>
<argument>${flags}</argument>
</arguments>
</configuration>
</plugin>
With the above plugin definition, I have available
# Launch
mvn package verify
# Calls [ launcher.bat ]
# Launch with debug flag
mvn package verify -Dflags=--debug
# Calls [ launcher.bat --debug ]
Then from my scripts, I can handle the --debug
flag, and if necessary, modify the launch command.
...
IF "%1"=="--debug" (
REM add VM arguments to suspend the JVM and wait for debugger to attach
SET vmOpts=%vmOpts% -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
REM some additional arguments to send to my application
SET extOpts=%extOpts% --debug --console
)
...
REM start the launcher.jar app with assemble arguments
START java %vmOpts% -jar launcher.jar %extOpts%
From with Eclipse, I now have 3 launch targets.
Standard Launch
A standard launch can be run by just running
mvn package verify
To debug, I require now two launch targets
Launch Debug
mvn package verify -Ddebug=--debug
This will cause the application to launch, and hang, waiting for the debugger to attach, from this point, I can run the second target from eclipse, which is simply configured to
Launch Debug Attach
This launch target simply connects to a remote application, as described in Eclipse's documentation.
Running this target connects to the running jvm, and the userspace code is resumed, allowing me to debug as normal - while the application is running out of the compiled dist directory.
Following this answer, I can simply export the three launch configurations, and commit them with the launcher itself, allowing new users of the repository to simply import the targets and be ready to go in seconds.