gpt4 book ai didi

java - Ant javac : package x does not exist, 但我将 x.jar 添加到 java 构建路径库

转载 作者:搜寻专家 更新时间:2023-11-01 01:21:53 24 4
gpt4 key购买 nike

我使用 ant 构建文件打开了一个现有项目。我收到很多关于 import x 无法解决的错误。我的项目文件夹中没有这些文件的 src 文件,但我有他们编译的 jar 文件。所以我转到 java build path -> libraries 并使用 add external JARs 将它们添加到我的项目中,我项目中的所有错误都消失了。

但是,现在当我通过运行 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;

所以相同的文件给我错误,但我修复了,但再次给我错误。我究竟做错了什么?我将 jar 文件添加到 java 构建路径库中,为什么 eclipse 找不到这些包?

这是 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>

最佳答案

添加libraries eclipse 构建路径不同于 Ant构建路径,让 Eclipse 编译你的项目,你所做的是正确的。但是为了使您的 ant 构建正常工作,您需要放置 libraries在您的 Ant 中定义的位置构建 xml。我想看看你的Ant构建 xml,您应该放置用于修复的库 import utilities.StringUtils ${vob.prefix}/swt/utilities/lib 中的问题检查线路

<property name="utilities.dir" value="${vob.prefix}/swt/utilities/lib"/>

关于java - Ant javac : package x does not exist, 但我将 x.jar 添加到 java 构建路径库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18660639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com