Solved

URGENT executable JAR with third party jars and property folder.

Posted on 2004-08-19
14
298 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:wizlokesh
  • 7
  • 5
  • 2
14 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11842715
You cannot put properties folder in the class-path option. Put it inside your jar file.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11842743
And use the getClass().loadResoureAsStream(<resource path>) to load it up.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11842753
Actually it's getResourceAsStream
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:wizlokesh
ID: 11843080
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.

0
 

Author Comment

by:wizlokesh
ID: 11843115
I mean i have the properties in some folder.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11843240
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?
0
 

Author Comment

by:wizlokesh
ID: 11843632
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.proerpties 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.main.MainClass
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.ExceptionInInitializerError: java.util.MissingResourceException: Can't fi
nd bundle for base name picklist, locale en
        at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
        at java.util.ResourceBundle.getBundleImpl(Unknown Source)
        at java.util.ResourceBundle.getBundle(Unknown Source)
        at com.aaa.bbb.sss.picklist.utils.PropertiesReader.readProperties(PropertiesReader.java:260)
        at com.aaa.bbb.sss.picklist.utils.PropertiesReader.<init>(PropertiesReader.java:69)
        at com.aaa.bbb.sss.picklist.utils.PropertiesReader.getInstance(PropertiesReader.java:97)
        at com.aaa.bbb.sss.picklist.main.PickListMain.<clinit>(PickListMain.java:59)

It clearly means that the picklist.properties which is master file is not found.

Please give your advice on the same.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11843851
Could you post the code that loads up the properties file?
0
 

Author Comment

by:wizlokesh
ID: 11843900
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.getProperty( 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.getBundle( 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;
    }

0
 
LVL 35

Expert Comment

by:girionis
ID: 11843909
Can you also post your classpath?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11844575
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("reading properties...");
      Properties properties = new Properties();
    try {
        properties.load(new java.io.FileInputStream("properties/LabelsBundle_de.properties"));
        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.
   
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 11846846
You'll need to either move your properties into a jar or run it using:

java -classpath picklist.jar;loging.jar;ifxjdbc.jar;property com.aaa.bbb.sss.picklist.main.MainClass
0
 

Author Comment

by:wizlokesh
ID: 11849236
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.....

0
 
LVL 92

Expert Comment

by:objects
ID: 11849282
> 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.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
Tomcat: Unable to run tomcat service. 2 24
Is there a simpler dropbox system? 10 35
Java Eclipse Loop 3 21
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question