SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Ant Classpath Problem

    Hi, I'm using Eclipse and Ant to create a Spring web application project which builds and deploys fine on its own, but when I add another project (a jar library) and call methods in the jar I get build errors from Ant. Does anyone know what I'm doing wrong?

    I've dropped the TestLibrary.jar into SpringSkeleton/WEB-INF/lib but the following compiler errors appear:

    Code:
    Buildfile: /Users/russell/Projects/Eclipse/SpringSkeleton/build.xml
    Compile:
        [javac] Compiling 1 source file to /Users/russell/Projects/Eclipse/SpringSkeleton/WEB-INF/classes
        [javac] /Users/russell/Projects/Eclipse/SpringSkeleton/src/springskeleton/controllers/ServerTimeController.java:10: 
    package testlibrary does not exist
        [javac] import testlibrary.Foo;
        [javac]                    ^
        [javac] /Users/russell/Projects/Eclipse/SpringSkeleton/src/springskeleton/controllers/ServerTimeController.java:19: 
    cannot find symbol
        [javac] symbol  : variable Foo
        [javac] location: class springskeleton.controllers.ServerTimeController
        [javac] 		String s = Foo.f();
        [javac]                            ^
        [javac] 2 errors
    
    BUILD FAILED
    ----

    build.xml for TestLibrary
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <project name="TestLibrary" basedir="." default="Build">
    	<property name="src.dir" value="src"/>
    	<property name="build.dir" value="bin"/>
    
    
    	<target name="Build" depends="Compile">
    		<jar destfile="TestLibrary.jar">
    			<fileset dir="." includes="**/*.class"/>
    		</jar>
    	</target>
    
    	<target name="Compile">
    		<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="build.classpath"/>
    		</javac>
    	</target>
    
    	<target name="Clean" description="Clean output directories">
    		<delete>
    			<fileset dir="${build.dir}">
    				<include name="**/*.class"/>
    			</fileset>
    		</delete>
    	</target>
    </project>
    ----

    build.xml for SpringSkeleton
    Code:
    <project name="SpringSkeleton" basedir="." default="Build">
    	<property file="build.properties"/>
    	<property name="src.dir" value="src"/>
    	<property name="build.dir" value="WEB-INF/classes"/>
    
    	<path id="build.classpath">
    		<fileset dir="WEB-INF/lib">
    			<include name="*.jar"/>
    		</fileset>
    		<fileset dir="${appserver.lib}">
    			<include name="*servlet*.jar"/>
    		</fileset>
    		<pathelement path="${build.dir}"/>
    	</path>
    
    	<target name="Build" depends="Compile">
    		<jar destfile="springskeleton.war">
    			<fileset dir="." includes="WEB-INF/**/*, jsp/**/*"/>
    		</jar>
    	</target>
    
    	<target name="Compile">
    		<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="build.classpath"/>
    		</javac>
    	</target>
    
    	<target name="Deploy">
    		<copy file="springskeleton.war" todir="${appserver.deploy}"/>
    	</target>
    
    	<target name="Clean" description="Clean output directories">
    		<delete>
    			<fileset dir="${build.dir}">
    				<include name="**/*.class"/>
    			</fileset>
    		</delete>
    	</target>
    </project>
    ----

    TestLibrary > src > testlibrary > Foo.java
    Code:
    package testlibrary;
    
    public class Foo {
    	public static String f() {
    		return "Test";
    	}
    }
    ----

    ServerTimeController.java
    Code:
    import <other_packages>;
    import testlibrary.Foo;
    
    
    public class ServerTimeController implements Controller {
    	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) 
    	throws ServletException, IOException {
    		ModelAndView modelAndView = new ModelAndView("servertime");
    		modelAndView.addObject("serverTime", new Date().toString());
    
    		String s = Foo.f();
    		
    		return modelAndView;
    	}
    }
    Thanks!
    Last edited by russell42; Nov 27, 2008 at 04:10.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •