Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Regarding Jar File

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 76070
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please give us full details of what you have in the manifest file.
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22662
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76070
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22662
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..?



 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply...

can you suggest me best obfuscators to use..
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you Google and research based off that, they change fairly rapidly.
 
No more fooling around. Read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic