Java — debug a maven program from Eclipse

I have a project in eclipse that has the following package structure after assembly

launcher.tar.gz
 |-- launcher.jar
 |-- lib/
 |-- resources/
 |-- plugins/

This is implemented using Maven - assembly - plugin

In order to start the application correctly, some resources are required, but they are not available outside the final assembly. In addition, I hope to have the ability to install plug-ins as they are now

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 starts in a paused state, I can attach a debugger and resume normal workflow

How can I simplify this process from eclipse?

I can get it from my launcher The Java class starts it, but when I debug in Eclipse, I can't install plug-ins in this way.

Solution

The following is an example of windows to do some of the methods you want Part of the idea is from here

I believe there are two ways to execute external commands with buttons in eclipse One is custom external tool configuration, and the other can be implemented through Maven running configuration in eclipse I will first display the external tool configuration:

The idea is to create a batch file at the root of the project directory and run it from eclipse by creating a new external tool configuration

So, for example, launcher. In your project directory Bat contains the following scripts:

call mvn clean package
call cd target/
call "C:\Program Files\Java\{jdkfolder}\bin\cjava.bat" -{your debug options} -jar launcher.jar

Where cjava Bat is another batch file that you need to create using the following script:

start /wait cmd.exe /c java %*

Then, your external program startup configuration may look like this, although I'm sure you'd rather set the working directory explicitly, so you don't have to highlight the project when you click Run

Set startup parameters in the public tab you select

Add this external configuration to your favorites for easy access (the external tools button should be on the taskbar)

Instead, if you really want to do this by using the run command, set a maven exec configuration (exec Maven plugin) and call the script file in this way. However, I haven't tried

<plugin>
                <artifactId>exec-maven-plugin</artifactId>
                <groupId>org.codehaus.mojo</groupId>
                <executions>
                    <execution>
                        <id>Launcher Remote Debug</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>${basedir}/launcher.bat</executable>
                </configuration>
            </plugin>

Then, you only need to delete the call of MVN clean package in the script file, so you won't end in an infinite loop

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>