2

I'm following along with this Springsource.org tutorial except I'm using Tomcat7 instead, and I'm encountering the following error whenever I run "ant list" or "ant reload" or "ant start".

/home/patchouli/workspace/springapp/build.xml:110: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at sun.net.NetworkClient.doConnect(NetworkClient.java:178)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:240)
at sun.net.www.http.HttpClient.New(HttpClient.java:321)
at sun.net.www.http.HttpClient.New(HttpClient.java:338)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:935)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:876)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:801)
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:210)
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:150)
at org.apache.catalina.ant.StartTask.execute(StartTask.java:44)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Here is my build.xml file:

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

    <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.6" target="1.6" 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>

<path id="catalina-ant-classpath">
    <fileset dir="${appserver.lib}">
           <include name="catalina-ant.jar"/>
           <include name="tomcat-coyote.jar"/>
           <include name="tomcat-util.jar"/>
        </fileset>
    <fileset dir="${appserver.home}/bin">
               <include name="tomcat-juli.jar"/>
    </fileset>
</path>  

<taskdef name="list" 
         classname="org.apache.catalina.ant.ListTask" 
         classpathref="catalina-ant-classpath"/>

<taskdef name="reload" 
         classname="org.apache.catalina.ant.ReloadTask" 
         classpathref="catalina-ant-classpath"/>

<taskdef name="start" 
         classname="org.apache.catalina.ant.StartTask" 
         classpathref="catalina-ant-classpath"/>

<taskdef name="stop" 
         classname="org.apache.catalina.ant.StopTask" 
         classpathref="catalina-ant-classpath"/>

<target name="reload">
    <reload url="${tomcat.manager.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"/>
</target>

<target name = "start">
    <start url="${tomcat.manager.url}"
                       username="${tomcat.username}"
                       password="${tomcat.password}"
                       path="/${webapp.name}"/>
</target>    

<target name = "stop">
       <stop url="${tomcat.manager.url}"
                         username="${tomcat.username}"
                         password="${tomcat.password}"
                         path="/${webapp.name}"
                         failonerror="false"/>
</target>

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

<target name="install">
    <install url="${tomcat.manager.url}"
             username="${tomcat.username}"
             password="${tomcat.password}"
             path="/${name}"
             war="${name}"/>
</target>

And my build.properties file:

# Ant properties for building the springapp

appserver.home=/usr/share/tomcat7
appserver.lib=${appserver.home}/lib

deploy.path=/var/lib/tomcat7/webapps

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

I am pretty frustrated. At the moment, I can just start tomcat7 manually and go to localhost:8080/springapp/index.jsp without any issue. But I want this to be automated using Apache Ant. It seems like the problem is that Ant cannot connect to Tomcat. Any thoughts?

maage
  • 21
  • 1
  • 2
  • Yes very strange indeed. You can try replacing localhost with the actual ip of your machine, but well...probably that won't make this work – Victor Apr 11 '13 at 21:37

4 Answers4

2

You seem to have similar problem I faced with Tomcat 7 and posted at ant target to deploy war to tomcat7/webapps.

Two Changes you need apply :

1) update tomcat manager url for Tomcat 7 (in build.properties)

# Ant properties for building the springapp

tomcat.manager.url=http://localhost:8080/manager/text

2) add extra manager role to user (in TOMCAT_DIRECTORY/conf/tomcat-users.xml)

    <role rolename="manager-script"/>

    <user username="admin" password="admin" roles="tomcat,manager-gui,manager-script"/>

MAKE SURE YOUR TOMCAT IS ALREADY RUNNING, BEFORE ant TRIES TO DEPLOY WAR.

Community
  • 1
  • 1
prayagupa
  • 30,204
  • 14
  • 155
  • 192
0

Do you have spaces or tabs after any of these lines in your build.properties?

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

They would be treated literally.

R C
  • 1
0

I had the same problem. If you are on windows maybe the paths cause this, because the tutorial is based on a linux OS. You can try backslasses (\) instead of (/)

appserver.home=\usr\share\tomcat7
appserver.lib=${appserver.home}\lib

deploy.path=\var\lib\tomcat7\webapps

To solve this I also replaced the variables with the absolute paths of tomcat's installation folder.

PetMarion
  • 147
  • 3
  • 14
0

Start the tomcat manually where it is installed.

  • Path of bat/sh : {tomcat--ver-}/bin/startup.

  • And then run the build.xml

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Desanth pv
  • 351
  • 1
  • 4
  • 13