Ant javac:包 x 不存在,但我将 x.jar 添加到 java 构建路径库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18660639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ant javac: package x does not exist, but i added the x.jar to the java build path libraries
提问by help
I opened an existing project using the ant buildfile. I got a lot of error about import x cannot be resolved. I don't have the src files for those in my project folder, but I have their compiled jar files. So I went to java build path -> libraries and used the add external JARs to add them to my project and all the error in my project went away.
我使用 ant 构建文件打开了一个现有项目。我有很多关于 import x 无法解决的错误。我的项目文件夹中没有这些文件的 src 文件,但我有他们编译的 jar 文件。所以我去了 java build path -> libraries 并使用添加外部 JAR 将它们添加到我的项目中,我的项目中的所有错误都消失了。
However, now when I build the project by running the ant file, i get
但是,现在当我通过运行 ant 文件构建项目时,我得到
[javac] Compiling 149 source files to X:\swt\documation\build
[javac] X:\swt\documation\src\swt\documation\bookshelf\objectmodel\Trans.java:20: package utilities does not exist
[javac] import utilities.StringUtils;
So the same files that gave me error but I though I fixed is giving me error again. What am I doing wrong? I added the jar file to the java build path library so why can't eclipse find these packages?
所以给我错误但我虽然我修复的相同文件再次给我错误。我究竟做错了什么?我在java构建路径库中添加了jar文件,为什么eclipse找不到这些包呢?
This is the build.xml file.
这是 build.xml 文件。
<?xml version="1.0"?>
<project name="documation" basedir="." default="packageApplication">
<condition property="vob.prefix" value="/cm_data" else="X:">
<os family="unix" />
</condition>
<property name="jar.keystore" value="${vob.prefix}/swt/cots/signJarKey"/>
<property name="oracle.cots.dir" value="${vob.prefix}/swt/cots/oracle/oracle/9.2.0"/>
<property name="utilities.dir" value="${vob.prefix}/swt/utilities/lib"/>
<property name="swt.mailer.dir" value="${vob.prefix}/swt/mailer/lib"/>
<property name="swt.logger.dir" value="${vob.prefix}/swt/logger/lib"/>
<property name="userprofile.dir" value="${vob.prefix}/swt/ups/lib"/>
<property name="apache.dir" value="${vob.prefix}/swt/cots/apache/apache/1.3.12"/>
<property name="jakarta.dir" value="${vob.prefix}/swt/cots/apache/jakarta"/>
<property name="frameworks.dir" value="${vob.prefix}/swt/cots/frameworks"/>
<property name="spring.dir" value="${frameworks.dir}/spring"/>
<property name="zk.dir" value="${frameworks.dir}/zk"/>
<property name="junit.dir" value="${vob.prefix}/swt/cots/junit"/>
<property name="vob.dir" value="."/>
<property name="webapp.name" value="documation"/>
<property name="src.dir" value="${vob.dir}/src"/>
<property name="bin.dir" value="${vob.dir}/bin"/>
<!-- This directory must be created view-private -->
<property name="build.dir" value="${vob.dir}/build"/>
<property name="web.dir" value="${vob.dir}/webapps"/>
<property name="dist.web.dir" value="${build.dir}/webapps"/>
<property name="lib.dir" value="${web.dir}/WEB-INF/lib"/>
<property name="tomcat.home" value="${vob.prefix}/swt/cots/apache/tomcat/6.0.28"/>
<property name="dist.dir" value="${vob.dir}/dist"/>
<property name="tmp.dir" value="${vob.dir}/temp"/>
<property name="report.dir" value="${vob.dir}/webapps/reports"/>
<path id="classpath">
<fileset dir="${junit.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${jakarta.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${apache.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${swt.logger.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${oracle.cots.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${utilities.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${swt.mailer.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${userprofile.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${tomcat.home}">
<include name="servlet*.jar"/>
</fileset>
<fileset dir="${frameworks.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${spring.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${zk.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="packageApplication" description="tar all application files"
depends="signJars" >
<tar destfile="${dist.dir}/documation.tar"
basedir="${tmp.dir}/webapp"
includes="**"
/>
</target>
<target name="signJars" depends="appletJar">
<signjar jar="${tmp.dir}/${webapp.name}-applet.jar"
alias="dmsKey"
keystore="${jar.keystore}"
storepass="dmsKey"
signedjar="${tmp.dir}/webapp/jsp/${webapp.name}-signed-applet.jar"
/>
<signjar jar="${vob.prefix}/swt/logger/lib/logger.jar"
alias="dmsKey"
keystore="${jar.keystore}"
storepass="dmsKey"
signedjar="${tmp.dir}/webapp/jsp/logger-signed.jar"
/>
<signjar jar="${vob.prefix}/swt/cots/apache/jakarta/commons-httpclient-3.0.1.jar"
alias="dmsKey"
keystore="${jar.keystore}"
storepass="dmsKey"
signedjar="${tmp.dir}/webapp/jsp/httpclient-signed.jar"
/>
<signjar jar="${vob.prefix}/swt/cots/apache/jakarta/commons-logging-api.jar"
alias="dmsKey"
keystore="${jar.keystore}"
storepass="dmsKey"
signedjar="${tmp.dir}/webapp/jsp/commonlogging-signed.jar"
/>
<signjar jar="${vob.prefix}/swt/cots/apache/jakarta/commons-codec-1.3.jar"
alias="dmsKey"
keystore="${jar.keystore}"
storepass="dmsKey"
signedjar="${tmp.dir}/webapp/jsp/commoncodec-signed.jar"
/>
</target>
<target name="appletJar" depends="documationJar">
<jar destfile="${tmp.dir}/${webapp.name}-applet.jar"
basedir="${build.dir}"
includes="swt/documation/dms/webdocs/client/*.class"
/>
</target>
<target name="documationJar" depends="zkStyleJar">
<jar destfile="${tmp.dir}/webapp/WEB-INF/lib/${webapp.name}.jar"
basedir="${build.dir}"
includes="swt/documation/bookshelf/**, swt/documation/dms/** swt/documation/objectmodel/** swt/documation/servlets/**"
excludes="swt/documation/dms/webdocs/client/*.class"
/>
</target>
<target name="zkStyleJar" depends="documationNGJar">
<jar destfile="${tmp.dir}/webapp/WEB-INF/lib/${webapp.name}-ZkStyle.jar"
basedir="${web.dir}/zkStyle"
includes="**"
/>
</target>
<target name="documationNGJar" depends="compileBuildDir">
<jar destfile="${tmp.dir}/webapp/WEB-INF/lib/${webapp.name}NG.jar"
basedir="${build.dir}"
includes="swt/documation/ng/** swt/documation/service/** swt/documation/web/**" />
</target>
<target name="compileBuildDir" description="Compile main source tree java files" depends="copyToTmp">
<javac destdir="${build.dir}" target="1.5" debug="true"
deprecation="false" optimize="true" failonerror="true">
<src path="${src.dir}"/>
<exclude name="test/swt/documation/service/**/*.java"/>
<classpath refid="classpath"/>
</javac>
</target>
<target name="copyToTmp" depends="cleanTmpDir">
<copy todir="${tmp.dir}/webapp">
<fileset dir="${web.dir}">
<exclude name="**/classes/**"/>
<exclude name="**/lib/*.jar"/>
<exclude name="**/zkStyle/**"/>
</fileset>
</copy>
</target>
<target name="cleanTmpDir">
<delete>
<fileset dir="${build.dir}" />
</delete>
<delete>
<fileset dir="${dist.dir}" />
</delete>
<delete>
<fileset dir="${tmp.dir}" />
</delete>
<mkdir dir="${tmp.dir}/webapp"/>
<mkdir dir="${tmp.dir}/webapp/lib"/>
</target>
<target name="reports" description="Compiles all the XML report designs and produces the .jasper files.">
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
<classpath refid="classpath"/>
</taskdef>
<jrc destdir="${report.dir}">
<src>
<fileset dir="${report.dir}">
<include name="**/*.jrxml"/>
</fileset>
</src>
<classpath refid="classpath"/>
</jrc>
</target>
</project>
采纳答案by Sajan Chandran
Adding libraries
to eclipse build path is different from Ant
build path, for eclipse to compile your project what you did is correct.
But for your ant build to work, you need to place the libraries
in location defined in your Ant
build xml.
I think by looking at your Ant
build xml, you should place your libraries for fixing import utilities.StringUtils
problem in ${vob.prefix}/swt/utilities/lib
check the line
添加libraries
到 eclipse 构建路径与Ant
构建路径不同,对于 eclipse 编译您的项目,您所做的是正确的。但是为了让您的 ant 构建工作,您需要放置libraries
在Ant
构建 xml 中定义的in 位置。我认为通过查看您的Ant
构建 xml,您应该将用于修复import utilities.StringUtils
问题的库放在${vob.prefix}/swt/utilities/lib
检查行中
<property name="utilities.dir" value="${vob.prefix}/swt/utilities/lib"/>
<property name="utilities.dir" value="${vob.prefix}/swt/utilities/lib"/>
回答by help
I think I figured the problem. In my build.xml file,
我想我想出了问题。在我的 build.xml 文件中,
<fileset dir="${utilities.dir}">
<include name="*.jar"/>
</fileset>
it is compiling those src files into jar files and using those jar files in those folder to compile my main program. Even though I added the jar files to my java build path libraries, eclipse is still looking for those jar files in those folders. So if i just put my jar files in those folder then my program works (why those src files didnt get automatically compiled into jar files is another problem, but at least my program compile now).
它正在将那些 src 文件编译成 jar 文件,并使用这些文件夹中的那些 jar 文件来编译我的主程序。即使我将 jar 文件添加到我的 java 构建路径库中,eclipse 仍然在这些文件夹中寻找那些 jar 文件。所以如果我只是把我的 jar 文件放在那些文件夹中,那么我的程序就可以工作(为什么那些 src 文件没有被自动编译成 jar 文件是另一个问题,但至少我的程序现在可以编译)。