java - 使用外部库通过 ANT 进行编译

标签 java eclipse ant

我是新用户 ANT我正在尝试编译我的 Eclipse 项目的一部分。我有很多类(class),但我只需要打包其中的一部分(请不要问为什么)。我的问题是这些类之一对放置在 <project_root>/libs 中的外部库的引用文件夹,我不知道如何链接它。我在网上找到了示例,但无法安排。

<path id="classpath">
    <fileset dir="libs" includes="**/*.jar"/>
</path>

<target name="compile">
    <mkdir dir="client/classes"/>
    <javac srcdir="src" destdir="client/classes" sourcepath="classpath">
        //include needed java files
    </javac>
</target>

我正在使用注释@RemoteEJB 。它位于 javax.ejb包裹。我收到错误:

package javax.ejb does not exist
[javac] import javax.Ejb.Remote;

最佳答案

如果我正确理解您的项目结构,则您的 ant 文件的问题在于您将类路径引用为源路径。

sourcepath/sourcepathref 指向可以找到源的位置。我想你想要的是 classpathref="classpath"。

<javac srcdir="src" destdir="client/classes" classpathref="classpath">
    //include needed java files
</javac>

关于java - 使用外部库通过 ANT 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19669889/

相关文章:

java - 使 Eclipse IDE 运行代码速度变慢

java - 在 Netbeans 中从 ant 迁移到 maven

java - 创建 android 项目时出错 Ionic 平台 android

java - JAXB 解码到托管 JPA 实体

java - 实数矩阵与复数矩阵相乘

php - 在 Eclipse 中使用 XDebug 远程调试时,PHP 源文件是否需要在本地和远程存在?

java - 添加一个 ant 目标以从 jar 文件中运行一个类

java - 从excel导入数据并在xpath的一部分中使用

java - 函数超时

java - 将 uri 转换为位图时出现 "No content provider execution "错误