Re: Running a Java app from command line

Discussion in 'Java' started by P.Hill, May 31, 2004.

  1. P.Hill

    P.Hill Guest

    Liz wrote:
    > Gee, you want to have jar files in different directories
    > but you don't want to tell the JVM where they are.


    Actually the OP only said he didn't want to alter the classpath,
    so I assumed specifying an explicit classpath on the command
    line, but I like your idea of links (assuming he is on
    a Unix variant.

    >>The app runs fine from the IDE, I suppose Eclipse
    >>takes care of all the dependencies.


    That sounds like the OP didn't throw in an extra jars, so maybe we
    are making it too difficult and the user just needs to learn to
    run java root of the classes tree for the classes which he built.

    -paul
     
    P.Hill, May 31, 2004
    #1
    1. Advertising

  2. P.Hill

    Abs Guest

    P.Hill wrote:
    > Liz wrote:
    >
    >> Gee, you want to have jar files in different directories
    >> but you don't want to tell the JVM where they are.

    >
    >
    > Actually the OP only said he didn't want to alter the classpath,
    > so I assumed specifying an explicit classpath on the command
    > line, but I like your idea of links (assuming he is on
    > a Unix variant.
    >
    >>> The app runs fine from the IDE, I suppose Eclipse
    >>> takes care of all the dependencies.

    >
    >
    > That sounds like the OP didn't throw in an extra jars, so maybe we
    > are making it too difficult and the user just needs to learn to
    > run java root of the classes tree for the classes which he built.
    >
    > -paul
    >


    This is the directory structure of my app:


    /com
    /domainname
    /mypackagename
    Class1.class
    Class2.class
    ....
    Class3.class
    extrajar1.jar
    extrajar2.jar
    .....
    extrajarn.jar
    MainApp.class


    If I try to run my app using:

    "java MainApp"

    it finds the classes in the com.domainname.mypackagename package, but it
    cannot find the classes in the extrajars, even though they are in the
    same directory as my main class.


    If I try to run it using the classpath parameter, like some of you told me:

    "java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"

    it cannot find the main class (WTF?), I get a
    "java.lang.NoClassDefError" error.


    Can someone help me, please ?


    regards

    --
    abs
     
    Abs, May 31, 2004
    #2
    1. Advertising

  3. P.Hill

    Ryan Stewart Guest

    "Abs" <> wrote in message news:...
    > This is the directory structure of my app:
    >
    >
    > /com
    > /domainname
    > /mypackagename
    > Class1.class
    > Class2.class
    > ....
    > Class3.class
    > extrajar1.jar
    > extrajar2.jar
    > ....
    > extrajarn.jar
    > MainApp.class
    >
    >
    > If I try to run my app using:
    >
    > "java MainApp"
    >
    > it finds the classes in the com.domainname.mypackagename package, but it
    > cannot find the classes in the extrajars, even though they are in the
    > same directory as my main class.
    >
    >
    > If I try to run it using the classpath parameter, like some of you told

    me:
    >
    > "java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"
    >
    > it cannot find the main class (WTF?), I get a
    > "java.lang.NoClassDefError" error.
    >

    You didn't specify the current directory in the classpath. "." is the
    current directory.
     
    Ryan Stewart, May 31, 2004
    #3
  4. P.Hill

    Abs Guest

    Ryan Stewart wrote:

    > "Abs" <> wrote in message news:...
    >
    >>This is the directory structure of my app:
    >>
    >>
    >>/com
    >> /domainname
    >> /mypackagename
    >> Class1.class
    >> Class2.class
    >> ....
    >> Class3.class
    >>extrajar1.jar
    >>extrajar2.jar
    >>....
    >>extrajarn.jar
    >>MainApp.class
    >>
    >>
    >>If I try to run my app using:
    >>
    >>"java MainApp"
    >>
    >>it finds the classes in the com.domainname.mypackagename package, but it
    >>cannot find the classes in the extrajars, even though they are in the
    >>same directory as my main class.
    >>
    >>
    >>If I try to run it using the classpath parameter, like some of you told

    >
    > me:
    >
    >>"java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"
    >>
    >>it cannot find the main class (WTF?), I get a
    >>"java.lang.NoClassDefError" error.
    >>

    >
    > You didn't specify the current directory in the classpath. "." is the
    > current directory.
    >
    >


    Thanks, it works now. But, I'd like to know why my first option don't
    work. Why it can find the classes in the unJARed package, but not the
    ones in the JARs.


    regards
     
    Abs, May 31, 2004
    #4
  5. P.Hill

    Ryan Stewart Guest

    "Abs" <> wrote in message news:...
    > Ryan Stewart wrote:
    > > "Abs" <> wrote in message

    news:...
    > >>If I try to run it using the classpath parameter, like some of you told

    > >
    > > me:
    > >
    > >>"java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"
    > >>
    > >>it cannot find the main class (WTF?), I get a
    > >>"java.lang.NoClassDefError" error.
    > >>

    > >
    > > You didn't specify the current directory in the classpath. "." is the
    > > current directory.
    > >
    > >

    >
    > Thanks, it works now. But, I'd like to know why my first option don't
    > work. Why it can find the classes in the unJARed package, but not the
    > ones in the JARs.
    >

    Because the root of your unJARed packages is the current directory. The root
    of a package in a JAR is not. A class file's full name is
    packageName.className, e.g. java.util.Vector. The first package, java in
    this example, must be a folder somewhere that the classpath points. A JAR
    has folders in it which are top level packages, so in order for Java to see
    them, the JAR must be in the classpath.
     
    Ryan Stewart, May 31, 2004
    #5
  6. P.Hill

    Abs Guest

    Ryan Stewart wrote:
    > "Abs" <> wrote in message news:...
    >
    >>Ryan Stewart wrote:
    >>
    >>>"Abs" <> wrote in message

    >
    > news:...
    >
    >>>>If I try to run it using the classpath parameter, like some of you told
    >>>
    >>>me:
    >>>
    >>>
    >>>>"java -classpath extrajar1.jar;extrajar2.jar;....;extrajarn.jar MainApp"
    >>>>
    >>>>it cannot find the main class (WTF?), I get a
    >>>>"java.lang.NoClassDefError" error.
    >>>>
    >>>
    >>>You didn't specify the current directory in the classpath. "." is the
    >>>current directory.
    >>>
    >>>

    >>
    >>Thanks, it works now. But, I'd like to know why my first option don't
    >>work. Why it can find the classes in the unJARed package, but not the
    >>ones in the JARs.
    >>

    >
    > Because the root of your unJARed packages is the current directory. The root
    > of a package in a JAR is not. A class file's full name is
    > packageName.className, e.g. java.util.Vector. The first package, java in
    > this example, must be a folder somewhere that the classpath points. A JAR
    > has folders in it which are top level packages, so in order for Java to see
    > them, the JAR must be in the classpath.
    >
    >


    Thank you very much for the info. Now I understand the whole classpath
    thing better.
     
    Abs, May 31, 2004
    #6
    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. Lucas Cowald
    Replies:
    4
    Views:
    1,102
    Tohid
    Oct 23, 2003
  2. Bernd Oninger
    Replies:
    1
    Views:
    819
    Martin Honnen
    Jul 7, 2004
  3. Replies:
    4
    Views:
    1,729
    Terry Hancock
    Apr 23, 2005
  4. Donald Duck

    Best command for running shell command

    Donald Duck, Jul 11, 2006, in forum: Python
    Replies:
    3
    Views:
    419
    iapain
    Jul 11, 2006
  5. Replies:
    3
    Views:
    535
    Daniel Pitts
    Jan 3, 2007
Loading...

Share This Page