我正在运行一个带有特定参数的 jar,例如: testscript run
然后这个测试脚本存在于不同的目录中,所以我使用 ant 的 java jar 命令运行该脚本的 jar,如下所示:
<java jar="testscript-jar.jar">
<arg value="run"/>
</java>
通过这样做,我收到错误无法找到或加载主类
。
此命令对于前 2-3 个实例运行良好,但对于其余目录开始显示错误。
最佳答案
确保 jar
属性指向 Jar 文件相对于 Ant 项目基目录的正确路径。请参阅 java
task documentation 中的这句话:
The parameter of the jar attribute is of type
File
; that is, the parameter is resolved to an absolute file relative to the base directory of the project, not the directory in which the Java task is run. If you need to locate a JAR file relative to the directory the task will be run in, you need to explicitly create the full path to the JAR file.
关于java - Ant jar 无法找到或加载主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31224816/