Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add classes to sun's rt.jar file?

I downloaded the Javax.mail package. I have jdk1.6.0_11. Problem is...I cannot get javac or java to find those classes! I can get apps to compile using JCreator LE ( by adding the mail jar to its search list ) but, when I try to run the app in a command window, it fails.

Can I add these new classes to the rt.jar without hurting my jdk installation? I know java has it wired up to look there for classes. (And, the mail classes are inside a javax package - seems like they could reasonably be added to the javax folder in rt.jar..

Thanks! Phil D'

like image 296
javaphild Avatar asked Apr 12 '09 19:04

javaphild


2 Answers

No you can't, nor should you.

Instead, figure out the problem with your classloader (probably paths?). You'll need that for the next library you need to access.

Messing with rt.jar means you can't run on any other JVM.

like image 88
Jason Cohen Avatar answered Sep 18 '22 18:09

Jason Cohen


You should either specify the jar file in your classpath: preferably on the command line with the -cp option, but possibly with the CLASSPATH environment variable.

Alternatively, you can specify its directory in the java.ext.dirs system property. For more details, see the documentation for the extensions mechanism.

You shouldn't be messing around with rt.jar. That's very definitely not the way to make extra jar files available - it's akin to trying to add Microsoft Word to the Windows kernel ;)

like image 33
Jon Skeet Avatar answered Sep 18 '22 18:09

Jon Skeet