0
votes

I am using ant to build my web-app. I am trying to include a property file in the WEB-INF folder from a source folder. I have included it in the war/WEB-APP/classes folder. But the application is not reading it. Hence, i want to include it in the WEB-INF folder directly to read it in the application. I have tried the following but nothing seems to work. my build.xml looks like this :

    <target name="build-dev" description="Package GWT app to web archive and deploy to web server">
   <echo message="Package GWT app to web archive" />
   <copy toDir="${basedir}/war/WEB-INF/lib">
      <fileset dir="${basedir}/lib" includes="*.jar" />
      <fileset dir="${gwt.home}" includes="*.jar" />
   </copy>
   <copy todir="${basedir}/war" file="${basedir}/src/etc/dev/GroupQuoteUI.properties" />
   <war basedir="${war.dir}" destfile="${deploy.dir}/${app.name}.war" webxml="${webinf.dir}/web.xml">
      <webinf dir="${webinf.dir}/">
         <include name="*." />

         <exclude name="**/web.xml" />
      </webinf>

      <classes dir="${basedir}/src/etc/dev/" includes="*.properties" />
   </war>
</target>

i have tried to use :

  1. "include name="${war.dir}/GroupQuoteUI.properties" in "webinf" tag but it did'nt worked.

  2. Also includes="${war.dir}/GroupQuoteUI.properties" inside the tag.

  3. Also this inside "webinf" folder again :

    "zipfileset dir="${basedir}/war/" includes="GroupQuoteUI.properties" fullpath="${webinf.dir}/GroupQuoteUI.properties"

but this is giving an error during build stating "cannot have src dir together".

So what should i do to include this file in the WEB-INF directory of the war. All other directories and web.xml file is included.

1
Could you show the code which reads the file?treeno
This code reads the GroupQuoteUI.properties file. BufferedInputStream stream = new BufferedInputStream (new FileInputStream("GroupQuoteUI.properties")); systemProperties.load(stream);sonal

1 Answers

0
votes

You cannot read a file that is packed into a war, or jar by accessing it with

new FileInputStream()

Instead you can do the following:

this.getClass().getResourceAsStream(filename)

this will load a resource (your properties-file) from the classpath, so it will read the file in a war-archive. It does this by using the same ClasseLoader which has been used to load the class that belongs to this.getClass()

Here you can find an example: How to really read text file from classpath in Java