• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Sheriff
Posts: 28399
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic