• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading java class from jar files  RSS feed

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • 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 ]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot Henry!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!