• Post Reply Bookmark Topic Watch Topic
  • New Topic

jars and c:\j2SDK1.4\jre\lib\ext  RSS feed

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mother of the stupid questions, I fear: but here is my problem: when I put my classes in a jar, and the jar in c:\j2SDK1.4\jre\lib\ext, the JRE does not find my classes:
%java myClass //does not work
%java -classpath %path%;c:\j2SDK1.4\jre\lib\ext //OK if the classes are NOT in a jar
%java -classpath %path%;c:\j2SDK1.4\jre\lib\ext\myJar.jar myClass //OK!
Is the purpose of "c:\j2SDK1.4\jre\lib\ext" not to be a folder where one can dumb one's jars? I must have forgotten something?
environment variables are all ok. I followed the rules found in the (EXCELLENT) book "Headlong.java"
Thanks for you time when considering this topic!
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "ext" directory is indeed a place where you can put JAR files and the JRE will load them. You don't and shouldn't put the "ext" dir on your CLASSPATH -- the JRE knows where it is already, and in fact uses a different class loader to load things out of that directory.
The other issue is that if you've got .class files in a directory, then you should add the directory to your class path; but if you've got a JAR file in a directory, then you should add the path to the JAR file, not the directory containing it, to the class path. So if you've for
C:\foo\Foo.class
C:\bar\bar.jar
The relevant classpath entries would look like
C:\foo\;c:\bar\bar.jar
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your respons, but it does not help me further: without using the classpath variable, why is the jre unable to find my classes-inside-jars when the jars are in C:\j2SDK1.4\jre\lib\ext? The jre finds them if I "point" to them with -cp, so I suppose there is nothing wrong with the way I create the jars. Or is it?
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To illustrate my point:
Consider this scenario:

I compile with:
%sources> javac -d ..\classes BibString.java
I put them in a jar:
%sources>cd ..
%sources>cd classes
%sources>cd jar -cvf myBib.jar Bib
I move myBib.jar to C:\j2SDK1.4\jre\lib\ext and
delete the folder Bib and the file BibStrings.java
Then I make this class:

Will it compile and run?
Yes, it compiles with:
%sources>javac Test.java
No, it does not run with
%sources>java Test ("No ClassDefFoundError ...")
but it does with this:
%sources>java -classpath C:\j2SDK1.4\jre\lib\ext\myBib.jar;. Test
Why is this if the JRE is always supposed to find things in C:\j2SDK1.4\jre\lib\ext?
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because Test.class needs a package-declaration too.
I'm not sure under which circumstances you exactly need a package-declaration, but:
If all your classes are in one Source-file and you only refer to the standard java-libs, then you needn't.
If your main class is in a package, every referred class has to be in package too I belief.
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not agreeing: (see code above)
There are 2 source files:
BibString.java (with package-declaration "Bib"): after compiling: Bib/BibString.class in jar (myBib.jar) and this one in c:/sdk1.4.1/jre/lib/ext and
Test.java (with main): after compiling Test.class can be "anywhere".
Thank you for your time anyway!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!