mvn 运行java 应用

一般我们可能都是使用的idea 工具,但是有时ide 工具可能不那么方便,可能就需要直接使用基于maven exec 插件的,以下是一个使用
的简单说明

exec 插件参考配置

  • 项目结构

  • 直接运行
mvn compile exec:java -Dexec.mainClass="com.dalong.App"
  • 配置插件
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <mainClass>com.dalong.App</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

运行就简单了mvn compile exec:java

  • 实际运行的参数
java -agentlib:jdwp=transport=dt_socket,address=9090,server=y,suspend=y -classpath /Users/xxxxx/.sdkman/candidates/maven/current/boot/plexus-classworlds-2.7.0.jar -Dclassworlds.conf=/Users/xxxx/.sdkman/candidates/maven/current/bin/m2.conf -Dmaven.home=/Users/xxxx/.sdkman/candidates/maven/current -Dlibrary.jansi.path=/Users/xxxx/.sdkman/candidates/maven/current/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/xxx/mylearning/jenkins/local-dev-jdwp-app org.codehaus.plexus.classworlds.launcher.Launcher compile exec:exec

运行时开启debug

有时可能需要进行debug 就需要开启下jdwp 协议,对于maven 3.3.1+ 版本的,直接可以配置jvm.config (当前项目的.mvn/jvm.config 文件)

  • 参考配置
-agentlib:jdwp=transport=dt_socket,address=9090,server=y,suspend=y

注意我配置suspend=y 可以按照自己项目的模式配置,因为我测试的是简单项目,不是long running 的,如果suspend=n 直接就退出了,不方便调试

说明

以上实际属于mvn 比较简单的使用,只是记录下

参考资料

https://www.mojohaus.org/exec-maven-plugin/

posted on 2024-06-05 11:06  荣锋亮  阅读(4)  评论(0编辑  收藏  举报

导航