[转] 使用maven运行java main的三种方式
原文地址:
http://blog.csdn.net/qbg19881206/article/details/19850857?utm_source=tuicool&utm_medium=referral
maven使用exec插件运行java main方法,以下是3种不同的操作方式。
一、从命令行运行
1、运行前先编译代码,exec:java不会自动编译代码,你需要手动执行mvn compile来完成编译。
mvn compile
2、编译完成后,执行exec运行main方法。
不需要传递参数:
mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main"
需要传递参数:
mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.args="arg0 arg1 arg2"
指定对classpath的运行时依赖:
mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.classpathScope=runtime
二、在pom.xml中指定某个阶段执行
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
将CodeGenerator.main()方法的执行绑定到maven的 test 阶段,通过下面的命令可以执行main方法:
mvn test
三、在pom.xml中指定某个配置来执行
<profiles>
<profile>
<id>code-generator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
将2中的配置用标签包裹后就能通过指定该配置文件来执行main方法,如下:
mvn test -Pcode-generator
注:通过以下命令可以获取mvn exec的其他配置参数说明。
mvn exec:help -Ddetail=true -Dgoal=java
英文地址:http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/
[转] 使用maven运行java main的三种方式的更多相关文章
- 使用Maven运行Java main的3种方式
使用Maven运行Java main的3种方式 原文 http://blog.csdn.net/qbg19881206/article/details/19850857 主题 Maven maven ...
- 使用Maven运行Java main的3种方式使用Maven运行Java main的3种方式
maven使用exec插件运行java main方法,以下是3种不同的操作方式. 一.从命令行运行 1.运行前先编译代码,exec:java不会自动编译代码,你需要手动执行mvn compile来完成 ...
- 使用Maven运行Java main的方法(转)
使用Maven运行Java Main的方法(既Java Application项目),可以有如下方式解决: 1.将Maven项目导入到eclipse中,然后直接项目右键[Run As]->[Ja ...
- Maven打jar包的三种方式
Maven打jar包的三种方式 不包含依赖jar包 该方法打包的jar,不包含依赖的jar包,也没有指定入口类. <build> <plugins> <plugin> ...
- Java线程的三种方式
创建线程有三种方式: 1.继承Thread类 2.实现Runnable接口 3.使用Callable和Future创建线程 三种方式详解如下: ---------------------------- ...
- java基础-jdbc——三种方式加载驱动建立连接
String url = "jdbc:mysql://localhost:3306/student?Unicode=true&characterEncoding=utf-8" ...
- (十一)Maven运行TestNG的testcase 两种方式:testng.xml和testngCase.java
原文:https://blog.csdn.net/wwhrestarting/article/details/46596869?utm_source=copy 1.通过maven-surefire-p ...
- java定时任务的三种方式
/** * 普通thread * 这是最常见的,创建一个thread,然后让它在while循环里一直运行着, * 通过sleep方法来达到定时任务的效果.这样可以快速简单的实现,代码如下 */ ...
- java 定时器的三种方式
原地址:http://blog.csdn.net/haorengoodman/article/details/23281343/ /** * 普通thread * 这是最常见的,创建一个thread, ...
随机推荐
- SGU107——987654321 problem
For given number N you must output amount of N-digit numbers, such, that last digits of their square ...
- 【JAVA - SSM】之MyBatis动态SQL
动态SQL就是在SQL语句中添加一些标签,以完成某些逻辑.通常用到的动态SQL标签有<if>.<choose>.<where>.<trim>.<s ...
- [Webpack 2] Expose modules to dependencies with Webpack
When you have a dependency that has dependencies on global variables (like jQuery or lodash) or assu ...
- [Javascript] The Array forEach method
Most JavaScript developers are familiar with the for loop. One of the most common uses of the for lo ...
- Servlet中的请求包含
public class SrcIncludeServlet extends HttpServlet { public void doGet(HttpServletRequest request, H ...
- Android开发之处理崩溃异常
众所周知,android的设备千差万别,难免会发生崩溃异常等现象,这个时候就需要捕获哪些崩溃异常了,也就是捕获崩溃异常的相关信息,并记录下来,这样一来方便开发人员和测试人员的分析与调试. 1.首先我们 ...
- react 组件开发
参考资料 https://toddmotto.com/react-create-class-versus-component/ React-Native的代码规范,React其实也基本一样~~ htt ...
- iOS 网络编程:AFNetworking
1 简介 1.1 概念 AFNetworking网络框架并不是IOS自带的框架,而是第三方的开源框架.它是对NSURLConnection和NSURLSession API的封装,但是目前AFNetw ...
- mysql mac 上启动
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist 中内容: <string>/usr/local/o ...
- C++学习(四)
一.拷贝构造函数和拷贝赋值运算符1.拷贝构造:用一个已有的对象,构造和它同类型的副本对象——克隆.2.形如class X { X (const X& that) { ... }};的构造函数 ...