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   荣锋亮  阅读(52)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-06-05 arroyo 0.3.0 新特性
2022-06-05 nchan 火焰图学习
2022-06-05 基于nchan 开发消息服务的一些核心知识点
2022-06-05 基于nchan 构建可靠的websocket 服务
2020-06-05 基于纯真ip库以及openresty 模仿实现类似搜狐ip获取区域的服务
2019-06-05 puppeteer 试用
2019-06-05 My journey introducing the data build tool (dbt) in project’s analytical stacks

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示