aspose file tools*
The moose likes Java in General and the fly likes Regarding Jar File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding Jar File" Watch "Regarding Jar File" New topic
Author

Regarding Jar File

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
In my application iam using some external libraries....
I want to build an executable jar file for my application....
I want the external jar files should also be present in the jar file....
I have tried, but failed to execute the jar file.....as my application unable to find the external jar files in classpath
I need help regarding...

Note:
--------
I have tried keeping the external library files outside the jar file and succeeded, but the requirement is different..
In this case i have come across one more problem, I have two java versions installed in my system Java 5 and 6.....Java 6 got installed because of some software
my application has some incompatibility issues with java 6 (especially with jdbc drivers)
while running jar file, it is giving some problem because of java version 6
Is there any way i can do some settings in jar file, so that the jar file run w.r.t jre version 5 instead of jre version 6
--------


thanks in advance

Abhishek
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
Please give us full details of what you have in the manifest file.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply...
here is the manifest file description
----------------------------------------------------

Main-Class: test.login
Class-Path: lib\sqljdbc.jar lib\swing-layout.jar lib\log4j.jar

--------------------------------------------
Directory structure

│-----sample.jar

└───lib
log4j.jar
sqljdbc.jar
swing-layout.jar

---------------------------------------------------
I want even these external jar files to be accessed from within the sample.jar file

Also let me know, is there any way i can mention the JRE path in the jar file, so that the application will run with respect to specified JRE
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41519
    
  53
Jar files can't be nested inside of other jar files if you want the JVM to load classes from them. You either need to distribute multiple jar files, or repackage all classes into a single jar file.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Ulf Dittmer wrote:Jar files can't be nested inside of other jar files if you want the JVM to load classes from them.

With some work it is possible, but it includes a custom class loader. One-JAR has managed to pull it off.

I still agree with you though that just delivering a set of JAR files should be just fine.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the replies..

With some work it is possible, but it includes a custom class loader. One-JAR has managed to pull it off.

Can you tell how it can be done?

Also let me know, is there any way i can mention the JRE path in the jar file, so that the application will run with respect to specified JRE

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
It might be easier to unzip all the .jar files and zip them up again into a single file.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Abhishek Reddy wrote:Can you tell how it can be done?

http://one-jar.sourceforge.net/

Also let me know, is there any way i can mention the JRE path in the jar file, so that the application will run with respect to specified JRE

That's not possible. You can use a BAT file to start your JAR file with a specific JRE, but think about what will happen if the user does not have that specific JRE, or has it installed at a different location.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks alot i wll try this out...

One more query....Is there any way i can stop users from extracting contents from a jar file....something like password protected jar files or encrypted kind of thing...

I not how can i restrict users from decompiling the application class files..?



Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

In short, it's not easy preventing users from unjarring a jar or decompiling your code (there may be some commercial products out there that I'm not aware of). Some people therefore use code obscuficators so that their code is not readable.

Certain types of Licensing also give you legal protection from people doing this.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks for the reply...

can you suggest me best obfuscators to use..
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I suggest you Google and research based off that, they change fairly rapidly.
 
 
subject: Regarding Jar File