---------Edit-----
So I've now come to realize that my errors are stemming from a command line launch rather than launching the jars by clicking on them. Essentially if I run the jars from any folder but the folder they actually reside in then my resources are incorrectly referenced. If I command line execute from the same folder this issue goes away. So the question becomes what can I do to reference the jar and resources relatively, regardless of where the execution is called from?
--------Edit------
I'm having several issues trying to get a project built for distribution. The project structure is such that I have 6 packages. Each package is split into two sub packages Gui and Engine. Each sub package has a runnable main class. The "Common" package is a wrapper for the other packages and launches whichever gets selected. My goal is to jar each package up into a standalone for the engine side of things. This is used for command line testing of the engine. The "Common" jar gets put together with all resources and runs the overall application.
My issue stems from a need to clean the project up. So re-factoring and repackaging are being done however the method used currently to build and jar the project is a batch script that copies class files(respecting package/folder structure) to the end folder location. From there the jars are created command line, and the class path and main class are outlined in a manifest file. This works just fine, the jars compile with the correct structure and classpath and everything runs correctly. However its a pain to keep the xcopy commands correct as it needs to be changed to whatever the package structure gets changed to, along with location depending on who is building the project.
So my solution was to use a build.xml and outline ant build for netbeans. This would respect any project structure changes and keep the build internal to netbeans. The exact issue I'm having is that regardless of the build method used.(Batch / Build script) I get the exact folder structure within the jars using either method, and the classpath is exactly the same. My common.jar works fine for the project, but my testing jars for the engine run into classpath or reference issues. I'll include the majority of the ant script, batch file, and the manifest file used.
Batch file
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Common C:\Emerson\Common\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Common\gui C:\Emerson\Common\gui\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Common\Meg C:\Emerson\Common\Meg\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Pressu re C:\Emerson\Pressure\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Pressure\Gui C:\Emerson\Pressure\Gui\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Pressure\Meg C:\Emerson\Pressure\Meg\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\PressureV2 C:\Emerson\PressureV2\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\PressureV2\Gui C:\Emerson\PressureV2\Gui\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\PressureV2\Gui\controller C:\Emerson\PressureV2\Gui\controller
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\PressureV2\Gui\models C:\Emerson\PressureV2\Gui\models
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\PressureV2\Gui\rules C:\Emerson\PressureV2\Gui\rules
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Temp\Gui C:\Emerson\Temp\Gui\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\Temp\Meg C:\Emerson\Temp\Meg\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\rfdFlow\Gui C:\Emerson\rfdFlow\Gui\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\rfdFlow\Meg C:\Emerson\rfdFlow\Meg\
xcopy /Y C:\Users\tfollansbee\Documents\NetBeansProjects\Emerson\branches\Merge\build\classes\utils C:\Emerson\utils\
"C:\Program Files\Java\jdk1.6.0_25\bin\jar" cvmf mainClass tempAsynch.jar Temp/*
"C:\Program Files\Java\jdk1.6.0_25\bin\jar" cvmf mainClass Common.jar Common/*
"C:\Program Files\Java\jdk1.6.0_25\bin\jar" cvmf pressureClass Pressure.jar Pressure/*
"C:\Program Files\Java\jdk1.6.0_25\bin\jar" cvmf pressureV2Class PressureV2.jar PressureV2/*
"C:\Program Files\Java\jdk1.6.0_25\bin\jar" cvmf rfdClass rfdFlow.jar rfdFlow/*
"C:\Program Files\Java\jdk1.6.0_25\bin\jar" cvmf pressureV2Class utils.jar utils/*
rmdir /s /q C:\Emerson\Common
rmdir /s /q C:\Emerson\Pressure
rmdir /s /q C:\Emerson\PressureV2
rmdir /s /q C:\Emerson\Temp
rmdir /s /q C:\Emerson\rfdFlow
rmdir /s /q C:\Emerson\utils
xcopy /Y C:\Emerson\Common.jar C:\GCCDEV
xcopy /Y C:\Emerson\tempAsynch.jar C:\GCCDEV
xcopy /Y C:\Emerson\Pressure.jar C:\GCCDEV
xcopy /Y C:\Emerson\PressureV2.jar C:\GCCDEV
xcopy /Y C:\Emerson\rfdFlow.jar C:\GCCDEV
xcopy /Y C:\Emerson\utils.jar C:\GCCDEV
Build script
<?xml version="1.0" encoding="UTF-8"?>
<project name="Emerson" default="default" basedir=".">
<description>Builds, tests, and runs the project Emerson.</description>
<property environment="env"/>
<property name="baseDir" value="build/classes/" />
<property name="cp" value=" . utils.jar lib/pfcasync.jar lib/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar lib/poi-3.7/poi-3.7-20101029.jar lib/poi-3.7/poi-ooxml-3.7-20101029.jar lib/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar lib/poi-3.7/ooxml-lib/dom4j-1.6.1.jar lib/xom/xom-1.2.7.jar lib/jgoodies/jgoodies-common-1.3.0.jar lib/jgoodies/jgoodies-binding-2.6.0.jar lib/resources/** Common.jar
" />
<import file="nbproject/build-impl.xml"/>
<target name="-pre-jar">
<echo message="-pre-jar" />
<delete dir="${env.PTC_STD}/lib/" />
<delete dir="${env.PTC_STD}/resources/" />
<!--delete dir="${env.PTC_STD}/build/" /-->
<echo message="aJar" />
<jar destfile="${env.PTC_STD}/Common.jar" basedir="${baseDir}">
<manifest>
<attribute name="Class-Path" value="${cp}" />
<attribute name="Main-Class" value="Common.gui.emersonWrapper" />
</manifest>
</jar>
<jar destfile="${env.PTC_STD}/tempAsynch.jar" index="false" basedir="${baseDir}" includes="Temp/**">
<manifest>
<attribute name="Class-Path" value="${cp}" />
<attribute name="Main-Class" value="Temp.Meg.tempasynch" />
</manifest>
</jar>
<jar destfile="${env.PTC_STD}/Pressure.jar" index="false" basedir="${baseDir}" includes="Pressure/**">
<manifest>
<attribute name="Class-Path" value="${cp}" />
<attribute name="Main-Class" value="Pressure.Meg.P3051STest" />
</manifest>
</jar>
<jar destfile="${env.PTC_STD}/PressureV2.jar" index="false">
<fileset dir="${baseDir}">
<include name="PressureV2/**" />
<include name="utils/**" />
</fileset>
<manifest>
<attribute name="Class-Path" value="${cp}" />
<attribute name="Main-Class" value="PressureV2.Gui.PressureV2Main" />
</manifest>
</jar>
<jar destfile="${env.PTC_STD}/rfdFlow.jar" index="false" basedir="${baseDir}" includes="rfdFlow/**">
<manifest>
<attribute name="Main-Class" value="rfdFlow.Meg.main" />
<attribute name="Class-Path" value="${cp}" />
</manifest>
</jar>
<jar destfile="${env.PTC_STD}/utils.jar" index="false" basedir="build/classes/" includes="utils/**">
<manifest>
<attribute name="Class-Path" value="${cp}" />
<attribute name="Main-Class" value="PressureV2.Gui.PressureV2Main" />
</manifest>
</jar>
<copy todir="C:/Emerson/resources/">
<fileset dir="resources/">
<exclude name="**/*.svn"/>
</fileset>
</copy>
<copy todir="C:/Emerson/lib/">
<fileset dir="lib/">
<include name="**/*.jar" />
<include name="**/resources/**" />
</fileset>
</copy>
</target>
</project>
Manifest file for common. The included class-path is the exact same in all other manifest files
Main-Class: Common.gui.emersonWrapper
Class-Path: . utils.jar lib/pfcasync.jar lib/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar lib/poi-3.7/poi-3.7-20101029.jar lib/poi-3.7/poi-ooxml-3.7-20101029.jar lib/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar lib/poi-3.7/ooxml-lib/dom4j-1.6.1.jar lib/xom/xom-1.2.7.jar lib/jgoodies/jgoodies-common-1.3.0.jar lib/jgoodies/jgoodies-binding-2.6.0.jar lib/resources/** Common.jar
At run time the jars all exist in the same folder along with a "lib" folder including all referenced library jars. Along with a few images and some xml data. The one difference I noticed in creating the jars was that the batch file did not create an index. Originally in my ant script I had index="true" and when running for example the pressure.jar I would get a java.lang.NoClassDefFoundError. I set the index="false" and my these errors go away, however my relative pathed xml files are not found in lib/resources/xml/a.xml The real kicker in all of this is the disparity between build methods. I've spent two days going over the jar structure, folder structure, and class-path. In the build.xml I even linked to the manifest files being used in the batch file to no success. Everything comes up the same so why the differences in the way these jars act at run time. I feel like there is a tiny detail that I'm missing.