• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading java class from jar files

 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My standalone java application uses a class whose implementation is in two different jar files. How do i force my application to use the implementation class from a specific jar file.

Does java -D solve it? If yes what parameters should i pass to the JVM?


Thanks in advance,
[ December 20, 2008: Message edited by: Srikanth Reddy ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java chooses the classfiles based on the order that they are found in the classpath. So, if you have two jar files, and you want one of them to be searched first for a particular class, just ensure that that jar file is listed earlier in the classpath.

Henry
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Henry Wong:
Java chooses the classfiles based on the order that they are found in the classpath. So, if you have two jar files, and you want one of them to be searched first for a particular class, just ensure that that jar file is listed earlier in the classpath.

Henry



The java class file is from Bootstrap entries so i cant change the order.
but i want to force jvm to use a different impl. for that class. Is it even possible?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Reddy:

The java class file is from Bootstrap entries so i cant change the order.
but i want to force jvm to use a different impl. for that class. Is it even possible?



Sorry, I don't believe so. The bootstrap takes precedence. It can even be used to replace classes of the standard Java runtime libraries. If you need to interpose a class in the bootstrap, you need to change the bootstrap order.

BTW, why aren't you allowed to change the bootclasspath?

Henry
[ December 20, 2008: Message edited by: Henry Wong ]
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry,

Actually i wanted to replace class from Java runtime library.

I have a class which is part of JRE 6. I have the same class implementation in a 3rd party library. I have to make use of the class from the 3rd party library replacing the class from the JRE 6 class.

How to acheive this? Sorry for the confusion caused in my previous post.

Thanks,
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the "-Xbootclasspath/p" option (don't forget about the "/p" part of that option). This option prepends classes to the bootclasspath.

However, be real careful using this option -- as classes that are prepended takes precedence, even over the core Java class files.

Henry
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Henry!
 
reply
    Bookmark Topic Watch Topic
  • New Topic