如何使用 ant 执行带有类路径的外部 jar 并使用 CI 参数
我遇到的情况是我已经带着一个罐子了。我不需要使用 ant 创建另一个 jar。另外,类路径也应该添加。
所以我的主要目标是使用 ant 运行下面的命令
示例如下:
java -cp myjar.jar -DParameterA=A -DParameterB=B com.mypackagename.package.ClassName
我也参考了下面的内容:
https://ant.apache.org/manual/Tasks/java.html
我正在使用如下命令:
ant -Dcom.test=TEST1 targetName
在 ant 的 build.xml 中,我正在尝试如下所示的操作:
<target name="readclass">
<java classname="${read-class}">
<classpath>
<pathelement location="myjar.jar"/>
</classpath>
<jvmarg value="-Xlingc"/>
<arg value="${com.test}"/>
</java>
</target>
但是使用我上面的代码我无法通过论据。 任何建议都会有帮助!
I have a situation where I have a jar already with me. I do not need to create another jar using ant. Also, classpath should add as well.
So my main goal is to run below command using ant
Example is as below:
java -cp myjar.jar -DParameterA=A -DParameterB=B com.mypackagename.package.ClassName
I have refer below as well:
https://ant.apache.org/manual/Tasks/java.html
I am using command like:
ant -Dcom.test=TEST1 targetName
In build.xml of ant I am trying something like below:
<target name="readclass">
<java classname="${read-class}">
<classpath>
<pathelement location="myjar.jar"/>
</classpath>
<jvmarg value="-Xlingc"/>
<arg value="${com.test}"/>
</java>
</target>
But using my above code I am not able to pass arguments.
any suggestion would be helpful!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
命令行上有不同类型的参数。类名之前的参数是 JVM 使用和消耗的参数,您可以通过 Ant 的
java
任务中的jvmarg
设置它们。类名后面的参数将发送到您的类,您可以通过arg
设置它们。jvmarg
的一个特殊情况是系统属性,当您使用命令行时,它是通过类名之前的-Dname=value
设置的。 Ant 为此提供了sysproperty
。jvmarg
要求任务的fork
属性设置为 true,因为默认情况下是在执行 Ant 的同一个 JVM 中运行该类,因此该类的参数已经已设置。这不适用于与所有fork
设置一起使用的sysproperty
。如果有疑问,请运行 ant -verbose ,它将为您提供 Ant 实际使用的命令行参数。
There are different kinds of arguments on the command line. The arguments that come before the class name are the arguments used and consumed by the JVM and you set them via
jvmarg
in Ant'sjava
task. Arguments after the class name are sent to your class and you set them viaarg
.A special case of
jvmarg
is the system property which is set via-Dname=value
before the class name when you use the command line. Ant providessysproperty
for that.jvmarg
s require the task'sfork
attribute to be set to true as the default is to run the class in the same JVM that is executing Ant and thus the arguments to that have already been set. This does not apply tosysproperty
which works with allfork
settings.If in doubt run
ant -verbose
which will provide you with the command line arguments Ant actually uses.扩展的@stefan bodewig答案..下面是对我有用的蚂蚁块
Extended @Stefan Bodewig answer .. below is the ant block which works for me