instanciate a class in a jar file with class.forname, while my main class is in another jar

C

cyril

Hi,

I got an INCOMPREHENSIBLE problem.

I am really not a newby in Java coding, and here is my problem :

I set my class path with several jars.

My main class is in my a jar nammed first.jar

During the code execution I do a class.forName (with the name getted
from a properties of text). And I get the classical message that it
couldn't find my classe.

The problem is that my 2 jars are in the classpath.

And more surprising :
java -cp $CLASSPATH my.main.class.MainClass -> does the class not
found exception
java -cp $CLASSPATH my.class.not.found.SecondaryClass -> does the no
main method ... what is normal but that shows a problem in the
classpath and jar management.

I was thinking too to the properties file encoding but with no success
(But I just try to mofify it with kate).

So if you can help me... i become crazy.... this error doesn't happen
on all my systems....

Actually I use a RH ES3.0 with JDK 1.4.2_05....

Txs a lot for reading me
 
S

Steve W. Jackson

:Hi,
:
:I got an INCOMPREHENSIBLE problem.
:
:I am really not a newby in Java coding, and here is my problem :
:
:I set my class path with several jars.
:
:My main class is in my a jar nammed first.jar
:
:During the code execution I do a class.forName (with the name getted
:from a properties of text). And I get the classical message that it
:couldn't find my classe.
:
:The problem is that my 2 jars are in the classpath.
:
:And more surprising :
:java -cp $CLASSPATH my.main.class.MainClass -> does the class not
:found exception
:java -cp $CLASSPATH my.class.not.found.SecondaryClass -> does the no
:main method ... what is normal but that shows a problem in the
:classpath and jar management.
:
:I was thinking too to the properties file encoding but with no success
:(But I just try to mofify it with kate).
:
:So if you can help me... i become crazy.... this error doesn't happen
:eek:n all my systems....
:
:Actually I use a RH ES3.0 with JDK 1.4.2_05....
:
:Txs a lot for reading me

Generally speaking, I find that there's no reason to ever set a
CLASSPATH variable, whether on Linux, Windows, whatever. Simply set the
classpath with the java command as you started to do.

It would appear from your examples that your CLASSPATH variable isn't
correct -- that is, it doesn't point to all the appropriate jar files.
So you might fix that problem in one of two ways. If your two jars are
always going to be together, make the manifest entries specify their
dependencies. Or just put them both in the classpath option you specify
on your java command. So long as all the classes referred to in your
code are available to the JVM at runtime, you should never encounter an
error saying the class isn't found.

= Steve =
 
C

cyril

:Txs a lot for reading me
Generally speaking, I find that there's no reason to ever set a
CLASSPATH variable, whether on Linux, Windows, whatever. Simply set the
classpath with the java command as you started to do.

It would appear from your examples that your CLASSPATH variable isn't
correct -- that is, it doesn't point to all the appropriate jar files.
So you might fix that problem in one of two ways. If your two jars are
always going to be together, make the manifest entries specify their
dependencies. Or just put them both in the classpath option you specify
on your java command. So long as all the classes referred to in your
code are available to the JVM at runtime, you should never encounter an
error saying the class isn't found.

= Steve =

Thanks Steve for your answer but my classpath is correct. I think what
I do is badly explained.
I use the '-cp $CLASSPATH' option when launching java.
- If the main class is my classical main class, inside I do a
class.forName("com.pack.A"). java doesn't find the class com.pack.A.
- If I try to lanch the class com.pack.A WITH THE SAME COMMAND AND
CLASSPATH (just to test if it's in my classpath) I got an error that
there is no main method (that's normal) and java doens't tell me that
it can't find the class, so *the class is in my classpath*.

I found a way to skip this problem by using JDK 1.3.1 !!! (and with
*the same command and classpath*) I don't know where the pb could be.
Does anyone heard about a different behavior in the class loader
between jdk 1.4.2_05 et 1.3.1 ?

Txs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top