wizlokesh
asked on
URGENT executable JAR with third party jars and property folder.
Need to create an executable jar which uses 2 third party jars and a properties folder.
All the three are outside the jar.
Tried doing class-path:cic.jar jdbc.jar property
But the properties folder was not taken as it gave me missiing resource exception.
The thing is it is not able to find the properties folder.
Dont know about the third party jars.
Please advice on the same
All the three are outside the jar.
Tried doing class-path:cic.jar jdbc.jar property
But the properties folder was not taken as it gave me missiing resource exception.
The thing is it is not able to find the properties folder.
Dont know about the third party jars.
Please advice on the same
You cannot put properties folder in the class-path option. Put it inside your jar file.
And use the getClass().loadResoureAsSt ream(<reso urce path>) to load it up.
Actually it's getResourceAsStream
ASKER
Well guys the thing is that the proeprty folder has things configurable which may be changed by client.
Hence I cannot keep it in the jar. Hence I need to have it in the some folder.
Please let me knwo If you know the same.
Hence I cannot keep it in the jar. Hence I need to have it in the some folder.
Please let me knwo If you know the same.
ASKER
I mean i have the properties in some folder.
Where do you currently have the properites files and how do you try to load them? Can you post some sample code and the exact exception you are getting?
ASKER
I have properties file in a property directory.
/property directory
picklist.properties
pickList.proeprties has entries of child proerpties
eg. picklist_sql.proeprties, picklist_messages.proerpti es etc.
The list.proeprties is read and then it loads the child proeprties.
I need to load these proeprties files memory when my Java program is executed.
Now when I execute my program using java com.aaa.bb.MainClass
it works fine.
But i create a exec jar of the same package with name as picklist.jar.
e.g. jar -cvfm picklist.jar MANIFEST.MF com
My Manifest MF is
Manifest-Version: 1.0
Main-Class: com.aaa.bbb.sss.picklist.m ain.MainCl ass
Created-By: 1.3.1_03 (Sun Microsystems Inc.)
Class-Path: loging.jar ifxjdbc.jar property
loging.jar and ifxjdbc are 3rd party. property is the name of folder where properties files are kept.
I use java -jar picklist.jar
exception is get is :
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r: java.util.MissingResourceE xception: Can't fi
nd bundle for base name picklist, locale en
at java.util.ResourceBundle.t hrowMissin gResourceE xception(U nknown Source)
at java.util.ResourceBundle.g etBundleIm pl(Unknown Source)
at java.util.ResourceBundle.g etBundle(U nknown Source)
at com.aaa.bbb.sss.picklist.u tils.Prope rtiesReade r.readProp erties(Pro pertiesRea der.java:2 60)
at com.aaa.bbb.sss.picklist.u tils.Prope rtiesReade r.<init>(P ropertiesR eader.java :69)
at com.aaa.bbb.sss.picklist.u tils.Prope rtiesReade r.getInsta nce(Proper tiesReader .java:97)
at com.aaa.bbb.sss.picklist.m ain.PickLi stMain.<cl init>(Pick ListMain.j ava:59)
It clearly means that the picklist.properties which is master file is not found.
Please give your advice on the same.
/property directory
picklist.properties
pickList.proeprties has entries of child proerpties
eg. picklist_sql.proeprties, picklist_messages.proerpti
The list.proeprties is read and then it loads the child proeprties.
I need to load these proeprties files memory when my Java program is executed.
Now when I execute my program using java com.aaa.bb.MainClass
it works fine.
But i create a exec jar of the same package with name as picklist.jar.
e.g. jar -cvfm picklist.jar MANIFEST.MF com
My Manifest MF is
Manifest-Version: 1.0
Main-Class: com.aaa.bbb.sss.picklist.m
Created-By: 1.3.1_03 (Sun Microsystems Inc.)
Class-Path: loging.jar ifxjdbc.jar property
loging.jar and ifxjdbc are 3rd party. property is the name of folder where properties files are kept.
I use java -jar picklist.jar
exception is get is :
Exception in thread "main" java.lang.ExceptionInIniti
nd bundle for base name picklist, locale en
at java.util.ResourceBundle.t
at java.util.ResourceBundle.g
at java.util.ResourceBundle.g
at com.aaa.bbb.sss.picklist.u
at com.aaa.bbb.sss.picklist.u
at com.aaa.bbb.sss.picklist.u
at com.aaa.bbb.sss.picklist.m
It clearly means that the picklist.properties which is master file is not found.
Please give your advice on the same.
Could you post the code that loads up the properties file?
ASKER
Its a singleton implementation.
private PropertiesReader( ) throws MissingResourceException
{
String fileList = null ;
String fileName = null ;
ArrayList listOfFiles = null ;
Properties properties = null ;
propertiesTable = new Hashtable() ;
nameofPropertiesFiles = this.readProperties( MASTER_PROP_FILE ) ;
fileList = nameofPropertiesFiles.getP roperty( APP_PROP_FILES ) ;
listOfFiles = readFurtherFiles( fileList ) ;
for ( int i=0; i < listOfFiles.size(); i++ )
{
fileName = ( String ) listOfFiles.get( i ) ;
properties = this.readProperties( fileName ) ;
propertiesTable.put( fileName, properties ) ;
}
}
private Properties readProperties( String fileName )
throws MissingResourceException
{
PropertyResourceBundle esProperties = null;
Properties properties = null;
Enumeration keys = null;
String keyTemp = null;
try
{
// Create object of PropertyResourceBundle for the filename
esProperties =
( PropertyResourceBundle )
PropertyResourceBundle.get Bundle( fileName );
}
catch( MissingResourceException missingResource )
{
throw missingResource;
}
properties = new Properties();
// Call getKeys method of PropertyResourceBundle to get all keys
keys = esProperties.getKeys();
// Using the key name, get corresponding value and populate
// properties object
while( keys.hasMoreElements() )
{
keyTemp = ( String )keys.nextElement();
properties.setProperty( keyTemp,
esProperties.getString( keyTemp ) );
keyTemp = null;
}
return properties;
}
private PropertiesReader( ) throws MissingResourceException
{
String fileList = null ;
String fileName = null ;
ArrayList listOfFiles = null ;
Properties properties = null ;
propertiesTable = new Hashtable() ;
nameofPropertiesFiles = this.readProperties( MASTER_PROP_FILE ) ;
fileList = nameofPropertiesFiles.getP
listOfFiles = readFurtherFiles( fileList ) ;
for ( int i=0; i < listOfFiles.size(); i++ )
{
fileName = ( String ) listOfFiles.get( i ) ;
properties = this.readProperties( fileName ) ;
propertiesTable.put( fileName, properties ) ;
}
}
private Properties readProperties( String fileName )
throws MissingResourceException
{
PropertyResourceBundle esProperties = null;
Properties properties = null;
Enumeration keys = null;
String keyTemp = null;
try
{
// Create object of PropertyResourceBundle for the filename
esProperties =
( PropertyResourceBundle )
PropertyResourceBundle.get
}
catch( MissingResourceException missingResource )
{
throw missingResource;
}
properties = new Properties();
// Call getKeys method of PropertyResourceBundle to get all keys
keys = esProperties.getKeys();
// Using the key name, get corresponding value and populate
// properties object
while( keys.hasMoreElements() )
{
keyTemp = ( String )keys.nextElement();
properties.setProperty( keyTemp,
esProperties.getString( keyTemp ) );
keyTemp = null;
}
return properties;
}
Can you also post your classpath?
Here is some sample code that works for me. I have a properties file called LabelsBundle_de.properties and its contents are:
# This is the LabelsBundle_de.properties file
s1 = Computer
s2 = Platte
s3 = Monitor
s4 = Tastatur
I use the java.util.Properties class to load it up from the disk and read the property keys:
static public void main(String[] args) {
System.out.println("readin g properties...");
Properties properties = new Properties();
try {
properties.load(new java.io.FileInputStream("p roperties/ LabelsBund le_de.prop erties"));
Enumeration e = properties.propertyNames() ;
while (e.hasMoreElements())
{
System.out.println("prop: " + ((String) e.nextElement()));
}
} catch (java.io.IOException e) {
}
} // main
I bundled my main class into a jar, I run it and it is working fine, it can read the properties file from the local disk. The structure of my jar file and the properties file is as follows:
---
PropertiesDemo.jar
properties---
LabelsBundle_de.properties
Hope it will give you an idea of how you can do it.
# This is the LabelsBundle_de.properties
s1 = Computer
s2 = Platte
s3 = Monitor
s4 = Tastatur
I use the java.util.Properties class to load it up from the disk and read the property keys:
static public void main(String[] args) {
System.out.println("readin
Properties properties = new Properties();
try {
properties.load(new java.io.FileInputStream("p
Enumeration e = properties.propertyNames()
while (e.hasMoreElements())
{
System.out.println("prop: " + ((String) e.nextElement()));
}
} catch (java.io.IOException e) {
}
} // main
I bundled my main class into a jar, I run it and it is working fine, it can read the properties file from the local disk. The structure of my jar file and the properties file is as follows:
---
PropertiesDemo.jar
properties---
LabelsBundle_de.properties
Hope it will give you an idea of how you can do it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I worked it out the other way.....
Instead of having executable JAR just create the jar of those files and keep it in classpath.
Execute using java com.aaa.vbbb.....
Instead of having executable JAR just create the jar of those files and keep it in classpath.
Execute using java com.aaa.vbbb.....
> I worked it out the other way.....
> Instead of having executable JAR just create the jar of those files and keep it in classpath.
Thats what I suggested :)
whether you specify the classpath on the command line, or use the env var does not make any difference.
> Instead of having executable JAR just create the jar of those files and keep it in classpath.
Thats what I suggested :)
whether you specify the classpath on the command line, or use the env var does not make any difference.