Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   instanciate a class in a jar file with class.forname, while my main class is in another jar (http://www.velocityreviews.com/forums/t136236-instanciate-a-class-in-a-jar-file-with-class-forname-while-my-main-class-is-in-another-jar.html)

cyril 08-20-2004 06:12 PM

instanciate a class in a jar file with class.forname, while my main class is in another jar
 
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

Steve W. Jackson 08-20-2004 06:27 PM

Re: instanciate a class in a jar file with class.forname, while my main class is in another jar
 
In article <3123d61c.0408201012.576706d@posting.google.com> ,
chico@grumly.info (cyril) wrote:

>: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


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 =
--
Steve W. Jackson
Montgomery, Alabama

cyril 08-25-2004 06:55 AM

Re: instanciate a class in a jar file with class.forname, while my main class is in another jar
 
>: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


All times are GMT. The time now is 02:15 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.