Question

I understand questions relating to this has been answered, but I have not come across this particular question answered in my search.

I've been trying to get my imported JAR files included in my build (shown below) of the spring application, but anything and everything I've done has not been the solution. I receive 'package does not exist' error when building in Eclipse using Tomcat and Ant because it cannot find the JAR files in the web-inf/lib folder (obviously). Eclipse does not allow me to drop and drag the files from the Referenced Library utility library to any desired folder. When I attempt to configure the build path, I add the external JARs and the directory path from which the file is located shows up next to the JAR in the libraries tab. The publish/export dependency is set to the WEB-INF/lib folder I've read adding all JAR files directly to the Tomcat/lib folder (which should not be done) could solve the issue but that's not the case for me. The deploy assembly path I set to /WEB-INF/lib for the JARs, no luck. I've tried restarting Eclipse, no luck. I created a new dynamic web project, no luck. I've unzipped the war file and no JAR files found, which is expected. I believe my environment variables are added correctly from

It's been years since I've played with Eclipse and Spring applications, so I expect I'm missing an important step.

NOTES: This is a Spring tutorial I've been working with to get back on my feet with Spring. Eclipse version 4.3.0 Tomcat version 6 Ant version 1.8.4 - was included as a plugin for Eclipse download

Any help will be greatly appreciated, since I would enjoy playing with web applications once again.

<project name="springapp1" basedir="." default="usage">
<property file="build.properties"/>

<property name="lib.dir" value="C:/Eclipse/Tomcat/lib"/>
<property name="webapps.dir" value="C:/Eclipse/Tomcat/webapps"/>

<property name="src.dir" value="src"/>
<property name="web.dir" value="WebContent"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="springapp1"/>

<path id="master-classpath">
    <fileset dir="${web.dir}/WEB-INF/lib">
        <include name="*.jar"/>
    </fileset>
    <!-- We need the servlet API classes: -->
    <!--  * for Tomcat 5/6 use servlet-api.jar -->
    <!--  * for other app servers - check the docs -->

    <!--<fileset dir="${appserver.lib}">-->
    <fileset dir="${lib.dir}">
        <include name="servlet*.jar"/>
    </fileset>
    <pathelement path="${build.dir}"/>
</path>

<target name="usage">
    <echo message=""/>
    <echo message="${name} build file"/>
    <echo message="-----------------------------------"/>
    <echo message=""/>
    <echo message="Available targets are:"/>
    <echo message=""/>
    <echo message="build     --> Build the application"/>
    <echo message="deploy    --> Deploy application as directory"/>
    <echo message="deploywar --> Deploy application as a WAR file"/>
    <echo message="install   --> Install application in Tomcat"/>
    <echo message="reload    --> Reload application in Tomcat"/>
    <echo message="start     --> Start Tomcat application"/>
    <echo message="stop      --> Stop Tomcat application"/>
    <echo message="list      --> List Tomcat applications"/>
    <echo message=""/>
</target>

<target name="build" description="Compile main source tree java files">
    <mkdir dir="${build.dir}"/>
    <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
           deprecation="false" optimize="false" failonerror="true">
        <src path="${src.dir}"/>
        <classpath refid="master-classpath"/>
    </javac>
</target>

<target name="deploy" depends="build" description="Deploy application">
    <copy todir="${webapps.dir}/${name}" preservelastmodified="true">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </copy>
    <echo message="Deploy Completed."/>
</target>

<target name="deploywar" depends="build" description="Deploy application as a WAR file">
    <war destfile="${name}.war"
         webxml="${web.dir}/WEB-INF/web.xml">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </war>
    <copy todir="${webapps.dir}" preservelastmodified="true">
        <fileset dir=".">
            <include name="*.war"/>
        </fileset>
    </copy>
</target>

<path id="catalina-ant-classpath">
    <!-- We need the Catalina jars for Tomcat -->
    <!--  * for other app servers - check the docs -->
    <fileset dir="C:/Eclipse/Tomcat/lib">
        <include name="catalina-ant.jar"/>
    </fileset>
</path>

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>

<target name="install" description="Install application in Tomcat">
    <install url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"
             war="${name}"/>
</target>

<target name="reload" description="Reload application in Tomcat">
    <reload url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name="start" description="Start Tomcat application">
    <start url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name="stop" description="Stop Tomcat application">
    <stop url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name="list" description="List Tomcat applications">
    <list url="${tomcat.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"/>
</target>

Was it helpful?

Solution

Drop the jars that need to be in the classpath of the deployed webapp (in WEB-INF/lib) under the WebContent/WEB-INF/lib product of the Eclipse project. That's all you need to do.

If you already added them to the project's build path, then remove them from there: everything under WebContent/WEB-INF/lib is automatically added to the build path.

OTHER TIPS

Try to use all jars to the classpath

<fileset dir="${lib.dir}">
    <include name="*.jar"/>
</fileset>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top