views:

681

answers:

1

Hey guys,

How exactly should I specify the location of all the properties files inside the ant manifest?

My jar is not working because it can't find the log4j, Spring, etc properties.

These files are all contained within a folder called "server-config" that sits at the same level as the source code, ie:

  • META-INF
  • com
  • server-config

Essentially, I want to know what I need to add to the Class-Path property for the jar to be aware of all these properties files inside the server-config folder.

Here's my current task:

<jar destfile="${root.home}/onejar/build/main/main.jar" basedir="${build.home}">
        <manifest>
            <attribute name="Class-Path" value=".;server-config" />
        </manifest>
        <include name="com/mycompany/client/*"/>
        <include name="com/mycompany/portable/util/*"/>
        <include name="com/mycompany/request/*"/>
        <include name="com/mycompany/model/*"/>
        <include name="com/mycompany/controller/*"/>
        <include name="com/mycompany/helpers/*"/>
        <include name="server-config/*"/>
    </jar>

I've tried a few things and none of them are working, I keep on getting errors due to the file not being found.

Any help would be greatly appreciated!

+2  A: 

You can remove the entire <manifest... part - that's not what the Class-Path manifest attribute does. It's for things external to the JAR.

The line <include name="server-config/*"/> should work - if the server-config directory exists inside your ${build.home} directory. You probably need a task to copy them there - you mention that the source code sits at the same level, but you don't mention where they are compiled to.

An example -

<mkdir dir="${build.dir}/server-config"
<copy todir="${build.dir}/server-config">
  <fileset dir="${src.dir}/server-config">
    <include name="*"/>
  </fileset>
</copy>
Nate
The server-config folder exists, as it is copied to the build.home during a previous task which this current task depends on. When I unzip the jar, it is all there, however when I try to run it, I get this http://snipt.org/lkt
So basically when I unzip the jar, I see the com folder (with the compiled source), META-INF and server-config. For some reason, it won't find anything....
That's because they're looking for their configuration files at the base of the classpath, and not one directory down in the server-config directory... instead of putting them in server-config, try copying the content of the server-config directory into ${build.dir} directly, so they will go into the base of the JAR.
Nate
If you do that, in the JAR task you posted, you'd need to remove <include name="server-config/*"/> and add includes to get your configuration files in the root - <include name="*"/> would get everything - <include name="*.properties"/> <include name="*.xml"/> if you wanted to be more selective.
Nate