开发者

Modify build.xml for another path for tomcat

开发者 https://www.devze.com 2023-04-12 08:39 出处:网络
This should be easy, but I\'m stuck trying to modify this build.xml I\'m getting from a tutorial. See below:

This should be easy, but I'm stuck trying to modify this build.xml I'm getting from a tutorial. See below:

<?xml version="1.0"?>

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

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

<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}">
        <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="${deploy.path}/${name}" preservelastmodified="true">
        <fileset dir="${web.dir}">
            <include name="**/*.*"/>
        </fileset>
    </copy>
</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="${deploy.path}" preservelastmodified="true">
        <fileset dir=".">
            <include name="*.war"/>
        </fileset>
    </copy>
</target>

<!-- ============================================================== -->
<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
<!-- ============================================================== -->

<path id="catalina-ant-classpath">
    <!-- We need the Catalina jars for Tomcat -->
    <!--  * for other app servers - check the docs -->
    <fileset dir="${appserver.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.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}"
             war="$开发者_开发知识库{name}"/>
</target>

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

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

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

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

<!-- End Tomcat tasks -->

</project>

I have tomcat installed at: C:\apache-tomcat-7.0.22, but the current file appears to be pulling in from the build.properties file:

# Ant properties for building the springapp

appserver.home=${user.home}/apache-tomcat-7.0.22

# for Tomcat 5 use $appserver.home}/server/lib
# for Tomcat 6 use $appserver.home}/lib

appserver.lib=${appserver.home}/lib

deploy.path=${appserver.home}/webapps

tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=tomcat
tomcat.manager.password=s3cret

and it's defaulting to my c:/documents and settings/etc...

I've never used properties files with ANT. How do I set this to point to my real tomcat directory?


Just change set appserver.home to C:\apache-tomcat-7.0.22 in the build.properties file

appserver.home=C:\apache-tomcat-7.0.22


I ran into issues with this, tutorial myself. The suggestion given does fix certain aspects of the problem but there is another issue that is overlooked, mainly due to the differences between Windows path names and other OS's like Linux. I was working with the springapp tutorial on two different computers and coulnd not get the build file to work correctly on one machine, even though I had set them up the same way in my IDE. As it turns out the issue has two possibilities; the path and location of your ANT and Tomcat server, and or the path and location to your eclipse or IDE workspace.

Windows has default install locations that sometimes invole folder names with spaces. If you are working from a command line you can simply surround the path name with single quotes, and be done with it. But, I found it easier to setup your workspace in a location with folders that do not have any spaces in them, and do the same for ANT and Tomcat. Try not to use the default install of Apache products in you Program Files folder put them somewhere on you C: drive, do the same for your IDE workspace, and you won't have as many issues, when your IDE is trying to resolve the classpath's.


Try using forward slash instead of backward slash i.e. C:/program files/.. and check . I had downloaded and unzipped apache in some other folder and it worked for me after changing the slash (at least not it gives a different error more to do with some tomcat file not available). Give it a go at your end too

0

精彩评论

暂无评论...
验证码 换一张
取 消