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

Discussion in 'Java' started by cyril, Aug 20, 2004.

  1. cyril

    cyril Guest

    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
    cyril, Aug 20, 2004
    #1
    1. Advertising

  2. In article <>,
    (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
    :mad: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 =
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, Aug 20, 2004
    #2
    1. Advertising

  3. cyril

    cyril Guest

    >: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
    cyril, Aug 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R2luZ2Vy?=
    Replies:
    2
    Views:
    627
    =?Utf-8?B?R2luZ2Vy?=
    Mar 1, 2004
  2. James Alan Farrell
    Replies:
    6
    Views:
    9,672
    Andrew Thompson
    Jan 9, 2004
  3. Adi Schwarz
    Replies:
    6
    Views:
    428
    Adi Schwarz
    Jan 29, 2004
  4. nashaccount

    Instanciate Excel into JSP page

    nashaccount, Jan 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,657
    kiranrajan
    Apr 11, 2010
  5. nguillot
    Replies:
    2
    Views:
    243
    nguillot
    May 26, 2011
Loading...

Share This Page