JarSplice修改命令行参数? [英] command line parameters with JarSplice?

查看:44
本文介绍了JarSplice修改命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JarSplice 允许将jar文件以及其他依赖项和库的聚合组合到一个可执行的jar文件中./p>

但是,我的可执行jar需要两个命令行参数,当我调用JarSplice jar时似乎根本没有传递这些参数.

在网站上,我没有看到任何有关如何做的事情,甚至可能的话.好奇是否有人遇到了这个问题,或者找到了可能的解决方案.

更新

我还应该补充一点,我的主类在JarSplice设置中指定,并且已成功调用.但是,如果我调用java -jar myjar.jar param1 param2,然后尝试打印param1和param2,则它们为null.

解决方案

我很害怕,这个工具有一些严重的缺陷.

它不只是在 fat.jar MANIFEST.MF 中设置您的 Main-Class ,而是设置它自己的 org.ninjacave.jarsplice.core.JarSpliceLauncher 作为 Main-Class .

然后,当您启动 fat.jar (使用 java -jar fat.jar )时,此 JarSpliceLauncher 类将启动使用 ProcesBuilder 的新过程,并且不会向其传递任何额外的参数.

对我来说,这只是 JarSplice 中的错误/错误设计.

现在,解决方法是将实际的 Main-Class 传递给 java 可执行文件,如下所示:

  java -cp fat.jar org.myawesomeapp.MyAwesomeClass [params ....] 

此外,还有其他(更好的)选项:

  1. 了解有关 Maven程序插件的信息,它是 jar-with-dependencies 描述符.
  2. 在Eclipse中,您可以使用导出 => 可运行的JAR =>选择将所需的库提取到生成的JAR 中.

JarSplice allows the aggregation of jar files and other dependencies and libraries to be combined into one executable jar file.

However, my executable jar requires two command line arguments, which don't seem to be passed at all when I call the JarSplice jar.

I didn't see anything on the site of how to do it, or if it's even possible. Curious if anyone had run into this issue, or found a possible solution.

Update

I should have also added that my main class is specified in the JarSplice setup, and is called successfully. However, if I call java -jar myjar.jar param1 param2, and then try and print param1 and param2, they are null.

解决方案

I'm affraid, this tool has some serious flaws.

Instead of just setting your Main-Class in the fat.jar MANIFEST.MF, it sets it's own org.ninjacave.jarsplice.core.JarSpliceLauncher as a Main-Class.

Then, when you start your fat.jar (using java -jar fat.jar) this JarSpliceLauncher class starts a new process using a ProcesBuilder and does not pass any extra parameters to it.

For me, its just a bug / bad design in the JarSplice.

Now, the workaround for this is to pass your actual Main-Class to java executable like this:

java -cp fat.jar org.myawesomeapp.MyAwesomeClass [params....]

Also, there are other (better) options:

  1. Read about Maven Assembly Plugin, and it's jar-with-dependencies descriptor.
  2. In Eclipse, you can use Export => Runnable JAR => Select Extract required libraries into generated JAR.

这篇关于JarSplice修改命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆