我无法使用Ant通过终端编译源代码,因为尽管我发出了'ant resolve或ant retrieve',但依赖关系似乎无法正确解析?
我的build.xml和下面的ivy.xml
的build.xml
<!-- ANT HOME ENVIRONMENT VARIABLE -->
<property name="ant.home" value="${env.ANT_HOME}" />
<!-- IVY HOME DIRECTORY -->
<property name="ivy.home" value="${ant.home}" />
<!-- IVY2 JAR DIRECTORY (REPOSITORY) -->
<property name="ivy.default.ivy.user.dir" value="${user.home}/.ivy2"/>
<!-- DOWNLOAD IVY -->
<target name="setup" description="Install ivy">
<mkdir dir="${user.home}/.ivy2" />
<get dest="${ivy.home}/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
</target>
<!-- RESOLVE CLASSPATHS -->
<target name="resolve" description="Use ivy to resolve classpaths">
<ivy:resolve file="ivy.xml" />
<ivy:report todir='target/ivy-reports' graph='false' xml='false'/>
<ivy:cachepath pathid="ivy.path" conf="compile" />
</target>
<!-- RETRIEVE DEPENDANCIES AFTER RESOLVING-->
<target name="retrieve" depends="resolve" description="Use ivy to retrieve dependencies">
<ivy:retrieve sync="true" type="jar" />
</target>
<!-- COMPILE PROJECT -->
<target name="compile" depends="clean, retrieve">
<!-- Create build directory -->
<mkdir dir="target/${ant.project.name}" />
<!-- Compile source code -->
<javac includeantruntime="false" srcdir="src" debug="true" destdir="target/${ant.project.name}" >
<classpath>
<path refid="ivy.path" />
</classpath>
</javac>
</target>
<!-- CLEAN TARGET DIRECTORY -->
<target name="clean">
<delete dir="target/orderlycalls" />
<delete dir="target/classes" />
<delete dir="target/ivy-reports" />
</target>
<!-- CLEAN TARGET AND IVY CATCHE -->
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
的ivy.xml
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<configurations>
<conf name="default" visibility="public" description="The single built artifact. Nothing else"/>
<conf name="compile" visibility="public" description="The master module and transitive dependencies"/>
<conf name="provided" visibility="public" description="Needed for compile. Will be provided outside or war"/>
<conf name="runtime" visibility="public" description="Not required for compile, but for runtime" extends="compile"/>
<conf name="default" visibility="public" description="The default configuration" extends="runtime"/>
<conf name="test" visibility="private" description="Required for testing" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="net.sf.trove4j" name="trove4j" rev="3.0.3" conf="provided"/>
<dependency org="org.apache.tomcat.embed" name="tomcat-embed-core" rev="7.0.53" conf="provided"/>
</dependencies>
</ivy-module>
当我运行'ant compile'时,on编译ant抱怨它无法找到'Servlet Context',它是tomcat.jar或'TObject'的一部分,'THashMap'是trove.jar的一部分,还有更多尽管我正在检索/解析build.xml中的jar。
我注意到的另一件事是我的.ivy2 / cache //里面没有实际的jar文件。只有xml文件
知道我做错了什么或根本不做什么?
由于
答案 0 :(得分:1)
您已使用cachepath任务创建Ant路径,使用与&#34; compile&#34;相关联的依赖项。组态。
<ivy:cachepath pathid="ivy.path" conf="compile" />
您的问题在于您的常春藤文件,您没有通过映射到&#34;编译&#34;来指定任何依赖项。组态。这可以解释为什么你的javac任务看不到任何罐子。
<configurations>
...
<conf name="compile" .../>
<conf name="provided" .../>
...
</configurations>
<dependencies>
<dependency ... conf="provided"/>
<dependency ... conf="provided"/>
</dependencies>
我建议为每个配置创建一个显式映射,例如:
<!-- Compile dependencies -->
<dependency org="net.sf.trove4j" name="trove4j" rev="3.0.3" conf="compile->default"/>
<!-- provided dependencies -->
<dependency org="org.apache.tomcat.embed" name="tomcat-embed-core" rev="7.0.53" conf="provided->master"/>
您唯一需要的映射是以下远程配置:
有关常春藤如何解释远程maven模块的更多信息,请阅读以下内容: