aspose file tools*
The moose likes Beginning Java and the fly likes class package directories in $JAVAHOME\jre\lib\ext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "class package directories in $JAVAHOME\jre\lib\ext" Watch "class package directories in $JAVAHOME\jre\lib\ext" New topic
Author

class package directories in $JAVAHOME\jre\lib\ext

Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Hi all,

I am just jumping back to Java after a 4 years break.

Here's my query:
I am playing around with a simple class of mine.
It is compiled for the package My.Pckg and is
called MyClass. I now place the .class file in the
lib\ext dir of the jre (including directory structure).

Now I have another class (AnotherClass) that instantiates
an instance of MyClass ( MyClass mc = new MyClass(); ).
I import the package "import My.Pckg.*;" in the java file.

But ... when I compile AnotherClass.java I reaceive the
message that the passsage does not exist.

OK, it works if I pass the lib\ext path to "javac" via the
"-classpath" option. But shouldn't the java-compiler *know*
where the ext dir is? Or are my system variables broken,
but then nothing would work?

What am I doing wrong?

Thanks in advance, Stuart
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306

But shouldn't the java-compiler *know*
where the ext dir is? Or are my system variables broken,
but then nothing would work?




What am I doing wrong?

You need to separate your code from sun supplied library. /lib is exclusively for sun libraries. classpath is the means to separate your classes.

In future if you need to upgrade your jre what will happen to your code. Putting in a separate directory under lib doesn't mean that you are separating your code from jre - here you are still relying on sun supplied directory structure.
[ December 22, 2005: Message edited by: jiju ka ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Jiju is right. Don't put your code in the extensions directory. If you do, then what will happen is this: first you will forget you did that. Then you will download a new version of the JRE. At this point you have a new extensions directory that doesn't contain your code and you will be baffled why things don't work any more.

However the answer to your question is that your class was in a package. The rules for classpath say that the directory containing the class's package must be in the classpath, not the directory containing the class itself.
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Thanks Jiju,
thanks Paul,

of course you are both correct about updating the
jre and not putting your own classes into the jre\lib\ext
dir.

BUT when learning Java this is what most books advice
you to do, to just test your classes quickly.

I know that the classpath must only contain the dir
that the package is in and not the dirs of the package
itself. I can get everything to work inside AND outside
the lib\ext dir with that info.

BUT the spec and all java beginner books say it is possible
to just plonk the classes (without jars) in the lib\ext
dir. I have seen that others have had this problem before me
and that others have not been able to reproduce this behaviour
either.

I am just befuddled about this whole business with the lib\ext
dir. BUT I will now keep my hands off it and ONLY work with
the classpath option and plonk my classes where I won't
forget them.

Thanks again, Stuart
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class package directories in $JAVAHOME\jre\lib\ext