java - 如何在 Ant 构建任务中将捆绑的 jar 添加到我的类路径中?
问题描述
我在 Eclipse 中有一个插件项目。我想用 ant 编译我的代码。现在我需要在我的类路径中添加一个 jar,它的类路径中也有几个 jar。导出了几个包,这些包是编译代码所必需的。当我将此 jar 添加到我的依赖项并使用 Eclipse 运行代码时,一切正常。但蚂蚁不知何故找不到所需的进口。捆绑 testfxplugin.jar 的清单:
Manifest-Version: 1.0
Automatic-Module-Name: dummyjar
Bundle-SymbolicName: dummyjar
Export-Package: com.sun.glass.ui.monocle,org.hamcrest,org.hamcrest.cor
e,org.hamcrest.internal,org.testfx.api,org.testfx.assertions.api,org.
testfx.assertions.impl,org.testfx.framework.junit,org.testfx.internal
,org.testfx.matcher.base,org.testfx.matcher.control,org.testfx.osgi,o
rg.testfx.osgi.service,org.testfx.robot,org.testfx.robot.impl,org.tes
tfx.service.adapter,org.testfx.service.adapter.impl,org.testfx.servic
e.finder,org.testfx.service.finder.impl,org.testfx.service.locator,or
g.testfx.service.locator.impl,org.testfx.service.query,org.testfx.ser
vice.query.impl,org.testfx.service.support,org.testfx.service.support
.impl,org.testfx.toolkit,org.testfx.toolkit.impl,org.testfx.util
Bundle-Name: Dummyjar
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: libs/openjfx-monocle-8u76-b04.jar,libs/testfx-core-4
.0.15-alpha.jar,libs/testfx-junit-4.0.15-alpha.jar,.,libs/org.hamcres
t.core_1.3.0.v201303031735.jar
Class-Path: libs/openjfx-monocle-8u76-b04.jar,libs/testfx-core-4
.0.15-alpha.jar,libs/testfx-junit-4.0.15-alpha.jar,.,libs/org.hamcres
t.core_1.3.0.v201303031735.jar
Bundle-ManifestVersion: 2
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
这是蚂蚁目标:
<path id="classpath.test">
<pathelement location="${test.lib}/testfxplugin.jar" />
<pathelement location="${test.lib}/junit-4.9.jar" />
</path>
<target name="test-compile">
<mkdir dir="${test.build}"/>
<javac srcdir="${test.src}" destdir="${test.build}" includeantruntime="false">
<classpath refid="classpath.test" />
</javac>
</target>
解决方案
正如@greg-449 所提到的,您必须将所有必需的 jar 添加为类路径的一部分。像这样的东西:
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
这只是包含多个(通配符条目)jar 的示例。您可以在Path-like Structures中了解更多信息
这基本上是一个传递依赖,即你的依赖有它们自己的依赖。这就是可以使用 Maven 的地方,它会自动处理这些依赖关系。更多信息:Maven 传递依赖
推荐阅读
- algorithm - 可变金额的有效再分配
- android - 在 Android 上使用生物识别身份验证保护加密密钥
- javascript - 打印功能引发错误,提示在 IE 11 中拒绝访问,但在 Chrome 上使用 localhost 没有问题
- iis - 使用查询字符串通过 IIS 重定向 URL
- r-lavaan - lavaan中具有多个组的多中介模型?
- reactjs - Material-UI Grid在使用显示时不隐藏
- android - 在调整大小时保持 AppWidget 中 ImageButton 的纵横比
- uml - UML 方法定义太长,无法放入类框
- python - 如何使用 Tkinter 将多个文本连接到一个滚动条
- java - How do you create an array list of objects from a text file and have each object be an array in java?