[英]Include libs folder containing .jars for compilation
I have the following file structure: 我具有以下文件结构:
ServerCode <- src , libs, bin
I am trying to compile all the code in src. 我正在尝试编译src中的所有代码。 Src has a couple of .java files at the top level and sub-directories. Src在顶层和子目录中有几个.java文件。 libs contains all the .jar files which are required to build my project. libs包含构建我的项目所需的所有.jar文件。
I wrote the following build.xml but when I try to compile it, the compiler throws errors cannot find symbol errors for the libraries I am including. 我写了下面的build.xml,但是当我尝试编译它时,编译器抛出错误,找不到包含的库的符号错误。
<project default="compile">
<target name="compile">
<mkdir dir="bin"/>
<javac srcdir="src" destdir="bin" classpath="libs/*.jar">
</target>
</project>
Define class path to include all jars like this 定义类路径以包括所有这样的罐子
<target name="compile" depends="" description="compile the java source files">
<javac srcdir="." destdir="${build}">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${test_lib}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
I don't think you can use a pattern in the classpath attribute. 我认为您不能在classpath属性中使用模式。 I could be wrong about this. 我对此可能是错的。 You should run ant in verbose mode (the -v option) to see how it's using your classpath attribute. 您应该在详细模式下运行ant(-v选项),以查看其如何使用classpath属性。 I suspect it's passing it to javac as a literal string. 我怀疑它会将它作为文字字符串传递给javac。
Here's what I do: 这是我的工作:
<javac target="${javac.target}" source="${javac.source}" destdir="${validator.output.dir}" debug="on"
nowarn="off"
memorymaximumsize="128m" fork="true">
<classpath refid="validator.module.production.classpath"/>
<src>
<dirset dir="Validator">
<include name="src"/>
</dirset>
</src>
</javac>
... ...
<path id="validator.module.production.classpath">
<fileset dir="Validator/lib/-validator" includes="**/*.jar"/>
</path>
Some of this code is generated by my IDE so it's a little verbose, but you get the idea. 其中一些代码是由我的IDE生成的,因此有些冗长,但是您明白了。
Try this as mentioned at http://ant.apache.org/manual/using.html instead of giving classPath attribute alongwith javac 尝试在http://ant.apache.org/manual/using.html上提到的方法,而不是将classPath属性与javac一起提供
<classpath>
<pathelement location="libs/*.jar"/>
</classpath>
There are other ways also which you can glance thru the link mentioned above 您还可以通过上述链接浏览其他方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.