[英]Please help me resolve my Ant + Ivy + Java build/dependency issues
I can get Eclipse to export a standalone JAR file which works fine. 我可以让Eclipse导出工作正常的独立JAR文件。 But when I try to use my build.xml file with Ant I get about 100 errors because a bunch of references can not be resolved. 但是当我尝试将我的build.xml文件与Ant一起使用时,由于无法解析大量引用,因此出现了大约100个错误。
Here is my build.xml 这是我的build.xml
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- =================================
target: resolve
================================= -->
<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:retrieve />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="resolve,clean, makedir">
<javac destdir="${build.dir}" includeantruntime="false">
<src path="${src.dir}"/>
<src path="${lib.dir}"/>
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\hcm.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="org.heromanager.MainWindow" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
Here is the ivy.xml file 这是ivy.xml文件
<ivy-module version="2.0">
<info organisation="org.herocombatmanager" module="mainwindow"/>
<dependencies>
<dependency org="org.apache.commons" name="commons-lang3" rev="3.0"/>
<dependency org="com.jgoodies" name="looks" rev="2.2.2"/>
<dependency org="com.jgoodies" name="forms" rev="1.2.1"/>
</dependencies>
</ivy-module>
And here are a few of the errors :-) 这是一些错误:-)
[javac] H:\Development\Workspace\HeroCombatManager\src\org\herocombatmanager\XMLParser.java:3: package org.apache.commons.lang3 does not exist
[javac] import org.apache.commons.lang3.StringUtils;
[javac] ^
[javac] H:\Development\Workspace\HeroCombatManager\src\org\herocombatmanager\AttackAdvantagesPanel.java:10: package com.jgoodies.forms.factories does not exist
[javac] import com.jgoodies.forms.factories.FormFactory;
[javac] ^
[javac] H:\Development\Workspace\HeroCombatManager\src\org\herocombatmanager\AttackAdvantagesPanel.java:11: package com.jgoodies.forms.layout does not exist
[javac] import com.jgoodies.forms.layout.*;
[javac] ^
...
[javac] H:\Development\Workspace\HeroCombatManager\src\org\herocombatmanager\AttackAdvantagesPanel.java:40: cannot find symbol
[javac] symbol : class FormLayout
[javac] location: class org.herocombatmanager.AttackAdvantagesPanel
[javac] this.setLayout(new FormLayout(new ColumnSpec[] {
[javac] ^
[javac] H:\Development\Workspace\HeroCombatManager\src\org\herocombatmanager\AttackAdvantagesPanel.java:40: cannot find symbol
[javac] symbol : class ColumnSpec
[javac] location: class org.herocombatmanager.AttackAdvantagesPanel
[javac] this.setLayout(new FormLayout(new ColumnSpec[] {
[javac] ^
Thank you all in advance.. 谢谢大家..
As @oers has pointed out, you cannot add the jar files in the "lib" directory as source files, the javac task doesn't work that way. 正如@oers指出的那样,您无法将jar文件添加到“ lib”目录中作为源文件, javac任务无法正常工作。
What you need to add the jars resolved by ivy to an ANT classpath. 您需要添加由常春藤解析的罐子到ANT类路径。 The simplest way to do this is to use the ivy cachepath task as follows: 最简单的方法是如下使用ivy cachepath任务:
<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:resolve/>
<ivy:cachepath pathid="compile.path"/>
</target>
<target name="compile" depends="resolve,clean, makedir">
<javac destdir="${build.dir}" includeantruntime="false" classpathref="compile.path">
<src path="${src.dir}"/>
</javac>
</target>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.