tags:

views:

363

answers:

4
+1  Q: 

ant deploy problem

I am working on a spring project. I use ant to deploy application and STS (eclipse based) IDE to develop. I set the CATALINA_HOME environment variable

 echo $CATALINA_HOME
/home/username/springsource/apache-tomcat

When I run the deploy ant task from IDE it deploys to a folder under

/home/username/workspace/myproject/${env.CATALINA_HOME}/webapp

but not

/home/username/springsource/apache-tomcat/webapp

Do you know any fix?

My build.properties file

src.dir=src
web.dir=web
build.dir=${web.dir}/WEB-INF/classes
name=myproject
appserver.home=${env.CATALINA_HOME}
deploy.path=${appserver.home}/webapps
appserver.lib=${appserver.home}/lib

and build.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project name="kervan" basedir="." default="usage">
<property environment="env"/>
<property file="build.properties"/>
<path id="cp">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${appserver.lib}">
<include name="servlet-api.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 a WAR file"/>
<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="cp"/>
</javac>
</target>
<target name="deploy" 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}" overwrite="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
</project>
A: 

Is CATALINA_HOME set in your environment?

e.g. Windows

echo %CATALINA_HOME%

Linux

echo $CATALINA_HOME

You could always hardcode the value in your properties file if it's not getting resolved correctly but provided it's in your environment then it should work.

The forum here discusses the same problem:

http://www.nabble.com/%3Cproperty-environment%3D%E2%80%9Denv%E2%80%9D%3E-doesn%27t-pick-up-an-environment-variable-td21481164.html

pjp
+2  A: 

Try putting the following after the two <property> lines:

<echo message="CATALINA_HOME=${env.CATALINA_HOME}" />

and see what it outputs. If it in fact outputs the correct value, then something strange may be happening. If it outputs the literal string

CATALINA_HOME=${env.CATALINA_HOME}

then somehow your ant script hasn't picked up the environment variable.

Note that when you set an environment variable for your system, only applications launched AFTER the variable is set will recognize the new variable. And variables set from the command line will only be recognized if the application being launched is being launched from that same command line session.

Adam Batkin
Ant echo is a nice way to check that it has been set.
pjp
A: 

When run from eclipse, I don't believe the environment is passed to ant. You will have to specify each of the environment variables (and the values) that you want passed to ant in the configuration of the build file within eclipse.

digitaljoel
A: 

If you're running from within Eclipse or an Eclipse-like environment, Eclipse can be kind of weird in that depending on how you launch it, it's startup scripts won't make your environment natively available to your in-IDE Ant build process.

With my Eclipse-based Ant build, I had to manually set the environment. So for me, I right click on my project & go to "Properties". Then I click on the "Builders" section. I select my "Ant Builder" and click "Edit...". Under this section there's an "Environment" tab where you can specify environment variables and their corresponding values.

Even if you're not using Eclipse exactly like I was, poke around in the build properties and you should be able to find a way to specify environment variables and make them available to the build process.

Brent Nash
Brent as you said I configured it from Builders section and it worked only when I hard-coded it to CATALINA_HOME=/home/username/springsource/apache-tomcat. I first assigned CATALINA_HOME to ${env_var:CATALINA_HOME} from preconfigured variables list but didnt work.
Gok Demir
@Gok: Yeah, it's annoying. You can try to use some of the internal Eclipse variables such as ${workspace_loc} if you're pointing to something under your workspace to make it not have to be an absolute path, but otherwise I think your only other choice is to mess with how you're launching Eclipse so that it gets your actual environment settings. What OS are you running on?
Brent Nash
I am running Ubuntu Jaunty. Anyway thanks for your solution.
Gok Demir