简体   繁体   English

如何在Ant构建任务中将捆绑的jar添加到类路径中?

[英]How can I add bundled jars to my classpath in an Ant build task?

I have a plugin-project in Eclipse. 我在Eclipse中有一个插件项目。 I want to compile my code with ant. 我想用ant编译我的代码。 Now I need to add a jar to my classpath, which has also a couple of jars in its classpath. 现在,我需要在我的类路径中添加一个jar,它的类路径中也有几个jar。 There are several packages exported, which are required to compile the code. 有几个导出的软件包,它们是编译代码所必需的。 When I add this jar to my dependencies and run the code with Eclipse, everything works fine. 当我将此jar添加到我的依赖项并使用Eclipse运行代码时,一切正常。 But ant somehow can't find the required imports. 但是蚂蚁不知何故找不到所需的进口。 The Manifest of the bundle testfxplugin.jar: 捆绑包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

Here is the ant-Target: 这是蚂蚁目标:

<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>

As mentioned by @greg-449, you will have to add all the required jars as part of classpath. 如@ greg-449所述,您将必须将所有必需的jar添加为类路径的一部分。 Something like this : 像这样的东西:

<classpath>
  <fileset dir="lib">
    <include name="**/*.jar"/>
  </fileset>
</classpath>

This is just an example to include multiple (wildcard entries) jars. 这只是包括多个(通配符条目)jar的示例。 You can read more about it at Path-like Structures 您可以在类似路径的结构中了解更多信息

This is basically a transitive dependency, ie your dependencies have their own dependencies. 这基本上是一个传递依赖,即您的依赖具有自己的依赖。 That is where Maven can be used, which automatically takes care of such dependencies. 那就是可以使用Maven的地方,它会自动处理此类依赖性。 More on it here : Maven Transitive Dependencies 此处更多信息: Maven传递依赖项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以将 jars 添加到 Maven 2 构建类路径而不安装它们吗? - Can I add jars to Maven 2 build classpath without installing them? 蚂蚁-javac任务-类路径未占用罐子 - Ant - javac task - classpath is not taking the jars 我可以要求ANT查看.classpath中的外部jar吗? - Can I ask ANT to look into .classpath for external jars? 如何在类路径中使用ant包含多个jar? - How can include multiple jars in the classpath using ant? 如何将JaCoCoverage添加到我的Ant构建过程中? - How can I add JaCoCoverage to my Ant build process? 如何在 Ant 中将类路径 jars 包含到 jar 中 - How to include classpath jars into a jar in Ant 使用Ant Build脚本创建WarFile时,如何在WEB-INF / lib文件夹中包含Classpath jars - How to include Classpath jars in WEB-INF/lib Folder while creating a WarFile using Ant Build Script 我可以在Jetty类路径中删除/添加jar而不重新启动它吗? - Can I remove/add jars in Jetty classpath without restarting it? 如何使用ant构建JavaME jar? 在JavaSE中运行时可以做到吗? - How do I build the JavaME jars with ant? and can i do it while running in javaSE? 我如何使用Ant来构建单个可执行文件.jar,该文件在.jar的/ lib目录中具有依赖项.jars? - How can I use Ant to build a single executable .jar that has dependency .jars in it in a /lib dir in the .jar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM