Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Ant build.xml not using correct properties file(My ant build.xml file only uses the 'local' properties file regardless of what target I specify)
Ant build.xml not using correct properties file [message #955504] Tue, 23 October 2012 21:16 Go to next message
Brendan Neff is currently offline Brendan Neff
Messages: 2
Registered: October 2012
Junior Member
I'm not well-versed in Ant, so I apologize if some of what I say doesn't make sense. Basically, we have 3 different targets that build our .war files with different properties so we can deploy to a local machine, dev, or production server. For some reason, one of my projects, regardless of which build option I select, will only use the properties file in the 'local' directory. Other projects with similar build files work fine, and to make it even stranger, other people in the office use this same build file without any problems (I have also closed the project, deleted it, deleted the folder, checked it out of SVN again, imported it back into eclipse, and still got the same result). I was hoping someone might have some insight into what could be causing this problem. I'll attach my build file below along with the start of the console output with ant running with the verbose argument (I can add more of the output, but I don't think most of it is relevant). Also, I'm running Eclipse Version: Helios Service Release 2 Build id: 20110218-0911 if that makes a difference.

build.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="ControlPanelApp" default="war-LOCAL">

	<dirname property="directory.base" file="${ant.file}" />
	
	<import file="${directory.base}/../build/ant/build-utils.xml"/>
	
	<!-- Initialize the Time Stamp -->
	<tstamp>
		<format property="YEAR" pattern="yyyy" />
	</tstamp>

	<dirname property="directory.base" file="${ant.file}" />
	<property name="directory.WEB-INF" value="${directory.base}/WebContent/WEB-INF" />
	<property name="directory.lib" value="${directory.base}/WebContent/WEB-INF/lib" />
	<property name="directory.build" value="${directory.base}/build" />
	<property name="directory.dist" value="${directory.base}/dist" />
	<property name="tomcat.lib" value="C:/Program Files/Apache Software Foundation/Tomcat 5.5/common/lib"/>

	<!-- Compiler options -->
	<property name="compiler.debug" value="on" />
	<property name="compiler.generate.no.warnings" value="off" />
	<property name="compiler.max.memory" value="128m" />

	<patternset id="ignored.files">
		<exclude name="**/CVS/**" />
		<exclude name="**/SCCS/**" />
		<exclude name="**/RCS/**" />
		<exclude name="**/rcs/**" />
		<exclude name="**/.DS_Store/**" />
		<exclude name="**/.svn/**" />
		<exclude name="**/.sbas/**" />
		<exclude name="**/.IJI.*/**" />
		<exclude name="**/vssver.scc/**" />
		<exclude name="**/vssver2.scc/**" />
	</patternset>

	<patternset id="compiler.resources">
		<include name="**/?*.properties" />
		<include name="**/?*.xml" />
		<include name="**/?*.gif" />
		<include name="**/?*.png" />
		<include name="**/?*.jpeg" />
		<include name="**/?*.jpg" />
		<include name="**/?*.html" />
		<include name="**/?*.dtd" />
		<include name="**/?*.tld" />
	</patternset>

	<path id="compile.classpath">
		<pathelement location="${directory.base}/build/classes" />
		<pathelement location="${directory.lib}/antlr.jar" />
		<pathelement location="${directory.lib}/activation.jar" />
		<pathelement location="${directory.lib}/barcodes.jar" />
		<pathelement location="${directory.lib}/commons-beanutils-1.7.0.jar" />
		<pathelement location="${directory.lib}/commons-chain-1.1.jar" />
		<pathelement location="${directory.lib}/commons-codec-1.3.jar" />
		<pathelement location="${directory.lib}/commons-digester-1.8.jar" />
		<pathelement location="${directory.lib}/commons-fileupload-1.2.jar" />
		<pathelement location="${directory.lib}/commons-httpclient-3.1.jar" />
		<pathelement location="${directory.lib}/commons-io-1.1.jar" />
		<pathelement location="${directory.lib}/commons-logging-1.0.4.jar" />
		<pathelement location="${directory.lib}/commons-validator-1.3.1.jar" />
		
		<pathelement location="${directory.lib}/crimson.jar" />
		<pathelement location="${directory.lib}/dwr.jar" />
		<pathelement location="${directory.lib}/google-checkout.jar" />
		<pathelement location="${directory.lib}/java-xmlbuilder-1.jar" />
		<pathelement location="${directory.lib}/jets3t-0.7.0.jar" />
		<pathelement location="${directory.lib}/mail.jar" />
		<pathelement location="${directory.lib}/oro-2.0.8.jar" />
		<pathelement location="${directory.lib}/pngencoder-1.0.jar" />
		<pathelement location="${directory.base}/../libs/servlet.jar" />
		<pathelement location="${directory.base}/../libs/log4j-1.2.8.jar" />
		<pathelement location="${directory.lib}/struts-core-1.3.8.jar" />
		<pathelement location="${directory.lib}/struts-taglib-1.3.8.jar" />
		<pathelement location="${directory.lib}/struts-tiles-1.3.8.jar" />
		<pathelement location="${directory.lib}/poi-3.0-alpha2-20060616.jar" />
		<pathelement location="${directory.lib}/poi-contrib-3.0-alpha2-20060616.jar" />
		<pathelement location="${directory.lib}/poi-scratchpad-3.0-alpha2-20060616.jar" />
	</path>
	
	<target name="init" description="Build initialization">
		<!-- Create the time stamp -->
		<tstamp />
	</target>


	<target name="clean" depends="init" description="cleaning directories">
		<delete dir="${directory.dist}" />
		<mkdir dir="${directory.dist}" />
		<delete dir="${directory.build}" />
		<mkdir dir="${directory.build}" />
		<mkdir dir="${directory.build}/classes" />
	</target>

	<target name="compile" depends="clean" description="Compiling">
		<javac destdir="${directory.build}/classes" debug="${compiler.debug}"
			nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}"
			fork="true" srcdir="${directory.base}/src">
			<classpath refid="compile.classpath" />
			<patternset refid="ignored.files" />
		</javac>

		<copy todir="${directory.build}/classes">
			<fileset dir="${directory.base}/src">
				<patternset refid="compiler.resources" />
				<type type="file" />
			</fileset>
		</copy>
		<copy todir="${directory.build}/classes">
			<fileset dir="${directory.base}/src">
				<exclude name="java/**" />
				<patternset refid="compiler.resources" />
				<type type="file" />
			</fileset>
		</copy>
	</target>

	<target name="-war" depends="compile" description="Will build everything and war it up">
		<war destfile="${directory.dist}/ControlPanelApp.war" webxml="${directory.WEB-INF}/web.xml">
			<fileset dir="${directory.base}/WebContent" casesensitive="yes" />
			<lib dir="${directory.lib}" casesensitive="true">
				<exclude name="**/servlet-api.jar" />
				<exclude name="**/jsp-api.jar" />
			</lib>
			<classes dir="${directory.build}/classes" includes="**/*" />
			<metainf dir="${directory.base}/WebContent/META-INF"
				casesensitive="true" />
		</war>
	</target>
	
	<target name="war-DEV" description="Set the DEV props into the war when building">
		<property name="directory.properties" value="${directory.base}/properties/dev" />
		<antcall target="-war"/>
	</target>

	<target name="war-LOCAL" description="Set the LOCAL props into the war when building">
		<property name="directory.properties" value="${directory.base}/properties/local" />
		<antcall target="-war"/>
	</target>

	<target name="war-PROD" description="Set the PROD props into the war when building">
		<property name="directory.properties" value="${directory.base}/properties/prod" />
		<antcall target="-war"/>
	</target>

</project>


console output:
Apache Ant version 1.7.1 compiled on June 27 2008
Buildfile: C:\src\controlpanelapp\build.xml
parsing buildfile C:\src\controlpanelapp\build.xml with URI = file:/C:/src/controlpanelapp/build.xml
Project base dir set to: C:\src\controlpanelapp
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
Importing file C:\src\build\ant\build-utils.xml from C:\src\controlpanelapp\build.xml
parsing buildfile C:\src\build\ant\build-utils.xml with URI = file:/C:/src/build/ant/build-utils.xml
Override ignored for property "directory.base"
Override ignored for property "YEAR"
Override ignored for property "DSTAMP"
Override ignored for property "TSTAMP"
Override ignored for property "TODAY"
Override ignored for property "directory.base"
Build sequence for target(s) `war-PROD' is [war-PROD]
Complete build sequence is [war-PROD, -compile-rules-engine, build-utils.-compile-domain-objects, build-utils.-compile-tools, init, clean, compile, -war, build-utils.-compile-client-request, -compile-sms, war-LOCAL, -compile-lender-ping-tree, build-utils.-compile-lender-ping-tree, build-utils.-compile-sms, -compile-domain-objects, -compile-client-request, build-utils.-compile-mapper, -compile-mapper, -compile-tools, war-DEV, build-utils.-compile-rules-engine, ]
war-PROD:
Project base dir set to: C:\src\controlpanelapp
  [antcall] calling target(s) [-war] in build file C:\src\controlpanelapp\build.xml
parsing buildfile C:\src\controlpanelapp\build.xml with URI = file:/C:/src/controlpanelapp/build.xml
Project base dir set to: C:\src\controlpanelapp
Override ignored for property "directory.base"
Importing file C:\src\build\ant\build-utils.xml from C:\src\controlpanelapp\build.xml
parsing buildfile C:\src\build\ant\build-utils.xml with URI = file:/C:/src/build/ant/build-utils.xml
Override ignored for property "YEAR"
Override ignored for property "DSTAMP"
Override ignored for property "TSTAMP"
Override ignored for property "TODAY"
Override ignored for property "directory.base"
Override ignored for property "file.reference.tools.jar"
Override ignored for property "file.reference.cmv-sms.jar"
Override ignored for property "file.reference.cmv-domain-objects.jar"
Override ignored for property "file.reference.cmv-mapper.jar"
Override ignored for property "file.reference.cmv-rules-engine.jar"
Override ignored for property "file.reference.cmv-lender-ping-tree.jar"
Override ignored for property "file.reference.cmv-client-request.jar"
Override ignored for property "file.reference.tools-build.xml"
Override ignored for property "file.reference.cmv-sms-build.xml"
Override ignored for property "file.reference.cmv-domain-objects-build.xml"
Override ignored for property "file.reference.cmv-mapper-build.xml"
Override ignored for property "file.reference.cmv-rules-engine-build.xml"
Override ignored for property "file.reference.cmv-lender-ping-tree-build.xml"
Override ignored for property "file.reference.cmv-client-request-build.xml"
Override ignored for property "YEAR"
Override ignored for property "DSTAMP"
Override ignored for property "TSTAMP"
Override ignored for property "TODAY"
Override ignored for property "directory.base"
Override ignored for property "directory.WEB-INF"
Override ignored for property "directory.lib"
Override ignored for property "directory.build"
Override ignored for property "directory.dist"
Override ignored for property "tomcat.lib"
Override ignored for property "compiler.debug"
Override ignored for property "compiler.generate.no.warnings"
Override ignored for property "compiler.max.memory"
Build sequence for target(s) `-war' is [init, clean, compile, -war]
Complete build sequence is [init, clean, compile, -war, -compile-rules-engine, build-utils.-compile-domain-objects, build-utils.-compile-tools, build-utils.-compile-client-request, -compile-sms, war-LOCAL, -compile-lender-ping-tree, build-utils.-compile-lender-ping-tree, build-utils.-compile-sms, -compile-domain-objects, -compile-client-request, build-utils.-compile-mapper, war-PROD, -compile-mapper, -compile-tools, war-DEV, build-utils.-compile-rules-engine, ]
  [antcall] Entering C:\src\controlpanelapp\build.xml...
Build sequence for target(s) `-war' is [init, clean, compile, -war]
Complete build sequence is [init, clean, compile, -war, -compile-rules-engine, build-utils.-compile-domain-objects, build-utils.-compile-tools, build-utils.-compile-client-request, -compile-sms, war-LOCAL, -compile-lender-ping-tree, build-utils.-compile-lender-ping-tree, build-utils.-compile-sms, -compile-domain-objects, -compile-client-request, build-utils.-compile-mapper, war-PROD, -compile-mapper, -compile-tools, war-DEV, build-utils.-compile-rules-engine, ]
init:
Override ignored for property "DSTAMP"
Override ignored for property "TSTAMP"
Override ignored for property "TODAY"
clean:
   [delete] Deleting directory C:\src\controlpanelapp\dist
   [delete] Deleting C:\src\controlpanelapp\dist\ControlPanelApp.war
   [delete] Deleting directory C:\src\controlpanelapp\dist
...


Inside the main project of the folder is a 'properties' folder that contains three folders, 'dev', 'local', 'prod', which each have a variety of .properties files. Every time I build the a .war, it uses the .properties files from the 'local' folder. I have confirmed this by changing values and even file names in the 'local' folder and can see that they were changed in the .war that is created.

Please let me know if there's any other information that I could provide to help troubleshoot this issue.
Re: Ant build.xml not using correct properties file [message #956587 is a reply to message #955504] Wed, 24 October 2012 16:31 Go to previous messageGo to next message
Russell Bateman is currently offline Russell Bateman
Messages: 3219
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 10/24/2012 2:36 AM, Brendan Neff wrote:
> I'm not well-versed in Ant, so I apologize if some of what I say doesn't
> make sense. Basically, we have 3 different targets that build our .war
> files with different properties so we can deploy to a local machine,
> dev, or production server. For some reason, one of my projects,
> regardless of which build option I select, will only use the properties
> file in the 'local' directory.
> [snip]

This is a lot of detail, but it's an ant not an Eclipse problem. If you
ran ant outside of Eclipse, you'd face the same problem. It's somewhat
unlikely you're going to get help from this forum.

I suggest that you're going to have to roll up your sleeves and get into
ant. There are a number of tricks to solve the problem you're facing;
you've chosen an approach that I don't use.

- My approach, for what it's worth ('cause you're still going to have to
learn to debug ant build scripts) is to include (not using the ant
include directive) a property file that is either missing or different
in the build environment depending what you want to happen. For example,
put this before other decisions are made:

<property file="somepath/build.properties" />

and use it to define things like whether it's a LOCAL, DEV or PROD
build. Then the rest of build.xml can know how to perform the build.

You see, somepath/build.properties, where this might be
/opt/neffprods/apps/controlpanels/conf/build.properties, will exist on
every build host, but it will be different because belonging to the
owner of the host. On your Jenkins build server, it will have whatever's
needed to do the production build (hypothetical example only).

- Note that, in ant, any time you define a property, the first
definition holds from then on. (Re-)defining it later in the build has
no effect. Use this to your advantage by making default definitions that
hold when somepath/build.properties is missing (because ant doesn't
complain that an included file is missing) or different but influences
the decisions made in defining properties later.

- If you have really big problems splitting hairs, you can resort to
using if-then-else from ant-contrib (Google for "ant if then else").
This requires adding an ant library JAR. It takes some experimentation
to figure out how to use it, but it can be useful to a) the beginning
ant coder and b) the ant build from hell that must have this sort of
power to solve its problems.

- Use built-in ant task <echoproperties /> to spill out the property
definitions here and there in your script and squint through them to
make sure they have the values you intend.

- Use ant -v to see much more about what ant is doing.

- I suggest using the latest possible version of ant. This will tend to
avoid problems of older version behavior which can be bewildering
sometimes, especially if the version of ant you're running from the
command line is different from the one in Eclipse. Don't use anything
older than ant 1.8.x. Typically, however, unless you're doing something
odd, this point isn't that important. (It just can be is all I'm saying.)

- Google "eclipse ant version" to get help with how to ensure you're
running the latest ant there.

- It doesn't matter whether you run ant inside of Eclipse or outside, it
should behave the same. Choose which seems easier to you. On Linux, this
would probably be a bash shell in my opinion.

- Google for help in ant using "ant <topic>". There is a LOT of help out
there.

Last, if you go to stackoverflow or another forum for ant help, you must
narrow your problem way down from what you've explained here or I doubt
you'll get much help. It's just to broad here as you've detailed it. You
get very fast answers to very pointed questions.

Best of luck to you.
Re: Ant build.xml not using correct properties file [message #956649 is a reply to message #956587] Wed, 24 October 2012 17:47 Go to previous message
Brendan Neff is currently offline Brendan Neff
Messages: 2
Registered: October 2012
Junior Member
Thanks, hopefully that will help me narrow down the question - part of the reason it's so broad was that I don't know enough about Ant to tighten it up. Your suggestions have at least given me some new directions to try, so they are much appreciated.
Previous Topic:Failed to install Package of "Eclipse IDE for C/C++ Developers"
Next Topic:Tomcat v7.0 failed to start
Goto Forum:
  


Current Time: Mon Oct 20 08:14:28 GMT 2014

Powered by FUDForum. Page generated in 0.05020 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software