Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant javac: package x does not exist, but i added the x.jar to the java build path libraries

Tags:

java

eclipse

ant

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.

However, now when I build the project by running the ant file, i get

 [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?

This is the build.xml file.

<?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>
like image 873
help Avatar asked Sep 06 '13 14:09

help


2 Answers

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

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

like image 189
Sajan Chandran Avatar answered Nov 01 '22 00:11

Sajan Chandran


I think I figured the problem. In my build.xml file,

 <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).

like image 2
help Avatar answered Oct 31 '22 23:10

help