• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Jar File

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please give us full details of what you have in the manifest file.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be easier to unzip all the .jar files and zip them up again into a single file.
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply...

can you suggest me best obfuscators to use..
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you Google and research based off that, they change fairly rapidly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic