maven打的包带exec包比不带的大,使用带有参数的Maven'exec:exec'

I have a project configured to build and run with Maven. The project depends on platform specific native libraries, and I'm using the strategy found here to manage those dependencies.

Essentially, the .dll or .so files for a particular platform are packaged into a jar, and pushed to the Maven server with a classifier identifying the target platform. The maven-dependency-plugin then unpacks the platform specific jar, and copies the native libraries to the target folder.

Normally I would use mvn exec:java to run a Java program, but exec:java runs applications in the same JVM as Maven, which prevents me from modifying the classpath. Since the native dependencies must be added to the classpath, I am forced to use mvn exec:exec instead. This is the relevant snippet of the pom:

...

org.codehaus.mojo

exec-maven-plugin

1.2.1

java

-Djava.library.path=target/lib

-classpath

com.example.app.MainClass

...

This works fine for the default configuration of the application, but I want to be able to specify some optional parameters at the command line. Ideally, I'd like to do something like this:

mvn exec:exec -Dexec.args="-a -b "

Unfortunately, specifying the exec.args variable overwrites the arguments I have in the pom (which are required to set up the classpath and run the application). Is there a way around this? What's the best way to specify some optional arguments at the command line without overwriting what I have in the pom?

解决方案

I managed to find a reasonably elegant solution to my problem using Maven environment variables.

The default values are defined as properties in the pom, and added to the exec plugin as arguments:

...

defaultA

defaultB

...

org.codehaus.mojo

exec-maven-plugin

1.2.1

java

-Djava.library.path=${project.build.directory}/lib

-classpath

com.example.app.MainClass

-a

${argumentA}

-b

${argumentB}

...

Now I can run with default parameters exactly as I did before:

mvn exec:exec

And I can easily override the defaults for each argument at the command line using:

mvn exec:exec -DargumentA=alternateA -DargumentB=alternateB

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值