java - Ant jar 无法找到或加载主类

标签 java ant jar classpath

我正在运行一个带有特定参数的 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/

相关文章:

java - ListView 返回相同的项目位置和 ID

Java 使用 JUnit 测试一个方法 (void)

android - 找不到项目文件 'Android' 中引用的平台 'san-angeles'

java - 如何将不同驱动器中的 jar 包含到 jar 文件中的 list 文件中

java - 使用扩展类的泛型

java - Spring:JSP 未读取传递的 ModelMap?

java - 使用 Ant 的类路径、编译和运行?

java - 如何从 Netbeans 从命令行创建的 ant 项目运行单个 junit 测试?

java - Windows 终端的 Jline3 问题

maven - 如何使用 Maven 将 rt.jar 嵌入到我的 WAR 中