Runs in Eclipse but not from command line

Discussion in 'Java' started by Tack, Jun 15, 2008.

  1. Tack

    Tack Guest

    I have built an application in Eclipse which goes through some JARs,
    retrieves the classes within them and introspects the classes to get more
    detailed info from them.

    I was getting NoClassDefFoundError issues when I tried to introspect some of
    the classes (at runtime obviously), which were resolved by adding the
    dependency JARs to the Eclipse build path for the project. Now the build
    path is configured the program is running fine in Eclipse.

    However, when I try to run the program from the command line I am getting
    the NoClassDefFoundError errors occurring again. It's pretty clear that the
    issues are classpath related. So I've tried the following commands (where
    jar1 and jar2 were added to the Eclipse build path):

    java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

    and

    set CLASSPATH=c:\jars\jar1.jar;c:\jars\jar2.jar
    java -jar myApp.jar

    .... but both fail to stop the NoClassDefFoundError problems. For some reason
    adding the JARs to the build path in Eclipse stops the issues, but setting
    the classpath via the command line doesn't.

    Any ideas?
     
    Tack, Jun 15, 2008
    #1
    1. Advertising

  2. On 15-6-2008 1:02, Tack wrote:
    > I have built an application in Eclipse which goes through some JARs,
    > retrieves the classes within them and introspects the classes to get
    > more detailed info from them.
    >
    > I was getting NoClassDefFoundError issues when I tried to introspect
    > some of the classes (at runtime obviously), which were resolved by
    > adding the dependency JARs to the Eclipse build path for the project.
    > Now the build path is configured the program is running fine in Eclipse.
    >
    > However, when I try to run the program from the command line I am
    > getting the NoClassDefFoundError errors occurring again. It's pretty
    > clear that the issues are classpath related. So I've tried the following
    > commands (where jar1 and jar2 were added to the Eclipse build path):
    >
    > java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar
    >
    > and
    >
    > set CLASSPATH=c:\jars\jar1.jar;c:\jars\jar2.jar
    > java -jar myApp.jar
    >
    > ... but both fail to stop the NoClassDefFoundError problems. For some
    > reason adding the JARs to the build path in Eclipse stops the issues,
    > but setting the classpath via the command line doesn't.
    >
    > Any ideas?

    When you use the -jar option, the JAR file is the source of all user
    classes, and other user class path settings are ignored. Though you can
    set a class path attribute in the manifest file.
    <http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html#-jar>
    <http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Main%20Attributes>
    --
    Regards,

    Roland
     
    Roland de Ruiter, Jun 15, 2008
    #2
    1. Advertising

  3. On Jun 15, 9:50 am, Roland de Ruiter
    <> wrote:
    > On 15-6-2008 1:02, Tack wrote:
    >
    > > I have built an application in Eclipse which goes through some JARs,
    > > retrieves the classes within them and introspects the classes to get
    > > more detailed info from them.


    Why? What does this do for the end user?
    ...
    > > java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

    ...
    > When you use the -jar option, the JAR file is the source of all user
    > classes, and other user class path settings are ignored. Though you can
    > set a class path attribute in the manifest file.


    Another way is to drop the jar option, add the
    main jar to the classpath, and call the main class
    explicitly.

    java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar;.\myApp.jar
    com.our.Main

    --
    Andrew T.
    http://pscode.org/
     
    Andrew Thompson, Jun 15, 2008
    #3
  4. On Jun 15, 2:43 pm, Lew <> wrote:
    > Andrew Thompson wrote:
    > > On Jun 15, 9:50 am, Roland de Ruiter
    > > <> wrote:
    > >> On 15-6-2008 1:02, Tack wrote:

    >
    > >>> I have built an application in Eclipse which goes through some JARs,
    > >>> retrieves the classes within them and introspects the classes to get
    > >>> more detailed info from them.

    > > ...
    > >>> java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

    > > ...
    > >> When you use the -jar option, the JAR file is the source of all user
    > >> classes, and other user class path settings are ignored.

    ...
    > > Another way is to drop the jar option, add the
    > > main jar to the classpath, and call the main class
    > > explicitly.

    ...
    > True, but "java -jar" is preferable - it treats the JAR as a deployable
    > application container, and describer of its own dependencies.
    >
    > Java's insistence that "java -jar" ignore the classpath is, uhh, jarring when
    > you first encounter it, but there's good reason for it.  Most of us aren't
    > used to thinking as deployers, only programmers.

    (snip reasoning..)

    Uh-huh (the penny drops). Finally that irritating
    behaviour of the jar option makes some sense*.

    It reminds me of many other deployment issues
    particularly related to both the application
    classpath and (slightly on a tangent) the security
    environment that I always wished that we could
    'tighten down' during development to get a better
    idea of the challenges of real world deployment.

    * Though it would be more ideal to be able to
    select the behavior explicitly, as a param to
    the java command, IMO.

    --
    Andrew T.
    http://pscode.org/
     
    Andrew Thompson, Jun 15, 2008
    #4
  5. Tack

    Tack Guest

    "Andrew Thompson" <> wrote in message
    news:...
    On Jun 15, 9:50 am, Roland de Ruiter
    <> wrote:
    > On 15-6-2008 1:02, Tack wrote:
    >
    > > I have built an application in Eclipse which goes through some JARs,
    > > retrieves the classes within them and introspects the classes to get
    > > more detailed info from them.


    > Why? What does this do for the end user?


    .... because the end-user wants an XML representation of the classes.
    Although this is besides the point.

    > > java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

    ....
    > When you use the -jar option, the JAR file is the source of all user
    > classes, and other user class path settings are ignored. Though you can
    > set a class path attribute in the manifest file.
    >
    >Another way is to drop the jar option, add the
    >main jar to the classpath, and call the main class
    >explicitly.
    >
    >java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar;.\myApp.jar
    >com.our.Main


    This is what I ended up doing. Thanks.
     
    Tack, Jun 15, 2008
    #5
  6. On Jun 15, 8:57 pm, "Tack" <> wrote:
    > "Andrew Thompson" <> wrote in message

    ...
    > > ...What does this do for the end user?

    >
    > ... because the end-user wants an XML representation of the classes.
    > Although this is besides the point.


    The point of the strategy perhaps, but not
    the point of the end goal.

    Is this a development tool?

    > >java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar;.\myApp.jar
    > >com.our.Main

    >
    > This is what I ended up doing. ...


    I am surprised, given the discussion that followed.

    How will you deploy the application?

    (There are deployment techniques that make
    a Manifest redundant, but for a 'plain old
    non-webstart app', it is very useful.)

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 15, 2008
    #6
  7. Tack

    Tack Guest

    "Andrew Thompson" <> wrote in message
    news:...
    On Jun 15, 8:57 pm, "Tack" <> wrote:
    >> "Andrew Thompson" <> wrote in message

    >...
    >> > ...What does this do for the end user?

    >>
    >> ... because the end-user wants an XML representation of the classes.
    >> Although this is besides the point.

    >
    >The point of the strategy perhaps, but not
    >the point of the end goal.
    >
    >Is this a development tool?


    Yes, it's a utility as part of a larger development tool.

    >> >java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar;.\myApp.jar
    >> >com.our.Main

    >>
    >> This is what I ended up doing. ...

    >
    >I am surprised, given the discussion that followed.


    Well, I actually did a hybrid of two suggestions. I updated the manifest
    with

    Class-Path: .

    .... and put myApp.jar into the same folder as the dependencies, navigated to
    the folder and used the following code to run the app:

    java -classpath jar1.jar;jar2.jar;myApp.jar com.our.Main

    >How will you deploy the application?


    It will be configured for my development environment, which is also shared
    as part of an Subversion repository.

    I cannot specify the dependency JARs within the manifest because they can
    change at run-time. The application will use the latest JARs build by other
    developers. These are versioned with different names, so I'm trying to make
    them configurable in the .bat file used to run the app.
     
    Tack, Jun 15, 2008
    #7
  8. Tack

    Tom Anderson Guest

    On Sun, 15 Jun 2008, Lew wrote:

    > Tack wrote:
    >> Well, I actually did a hybrid of two suggestions. I updated the manifest
    >> with
    >>
    >> Class-Path: .

    >
    > No one suggested that.
    >
    > <http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Main
    > Attributes>
    >
    >> ... and put myApp.jar into the same folder as the dependencies, navigated
    >> to the folder and used the following code to run the app:
    >>
    >> java -classpath jar1.jar;jar2.jar;myApp.jar com.our.Main

    >
    > Better would be:
    >
    > Manifest has
    > Main-Class: com.our.Main
    > Class-Path: jar1.jar jar2.jar
    >
    > Deployment has all three JARs in the same directory, call it /usr/foo/.


    I think the OP needs to be able to vary the set of depended-on JARs at
    runtime - this is essentially a kind of plugin mechanism. That means
    specifying them in the app JAR's manifest won't work. Unless i've
    misunderstood what you're doing here.

    > $ cd /usr/foo
    > $ jar -jar myApp.jar


    Yousa thinking yousa jars ganna run?

    tom

    --
    That must be one of the best things you can possibly do with a piglet,
    booze and a cannon. -- D
     
    Tom Anderson, Jun 15, 2008
    #8
  9. Tack

    Tack Guest

    "Tom Anderson" <> wrote in message
    news:p...
    > On Sun, 15 Jun 2008, Lew wrote:
    >
    >> Better would be:
    >>
    >> Manifest has
    >> Main-Class: com.our.Main
    >> Class-Path: jar1.jar jar2.jar
    >>
    >> Deployment has all three JARs in the same directory, call it /usr/foo/.

    >
    > I think the OP needs to be able to vary the set of depended-on JARs at
    > runtime


    This is exactly what I'm trying to do.
     
    Tack, Jun 15, 2008
    #9
  10. Tack

    Arne Vajhøj Guest

    Andrew Thompson wrote:
    > On Jun 15, 2:43 pm, Lew <> wrote:
    >> True, but "java -jar" is preferable - it treats the JAR as a deployable
    >> application container, and describer of its own dependencies.
    >>
    >> Java's insistence that "java -jar" ignore the classpath is, uhh, jarring when
    >> you first encounter it, but there's good reason for it. Most of us aren't
    >> used to thinking as deployers, only programmers.

    > (snip reasoning..)
    >
    > Uh-huh (the penny drops). Finally that irritating
    > behaviour of the jar option makes some sense*.


    I would put it even more directly: end users typical
    want just to double click on the jar file. That fits
    well with the -jar implementation while explicit use
    of -cp would not work for that category of users.

    Arne
     
    Arne Vajhøj, Jun 15, 2008
    #10
  11. Tack wrote:
    > "Tom Anderson" <> wrote in message
    > news:p...
    >> On Sun, 15 Jun 2008, Lew wrote:
    >>
    >>> Better would be:
    >>>
    >>> Manifest has
    >>> Main-Class: com.our.Main
    >>> Class-Path: jar1.jar jar2.jar
    >>>
    >>> Deployment has all three JARs in the same directory, call it /usr/foo/.

    >>
    >> I think the OP needs to be able to vary the set of depended-on JARs at
    >> runtime

    >
    > This is exactly what I'm trying to do.


    Well, then how about using your own class loader and invooke the program
    along the lines "java -jar myapp.jar jar-to-inspect-1.jar
    jar-to-inspect-2.jar ...

    --
    Roger Lindsjö
     
    Roger Lindsjö, Jun 15, 2008
    #11
  12. On Jun 15, 9:50=A0am, Roland de Ruiter
    > On 15-6-2008 1:02, Tack wrote:
    >
    > > I have built an application in Eclipse which goes through some JARs,
    > > retrieves the classes within them and introspects the classes to get
    > > more detailed info from them.


    Why? What does this do for the end pigfucker?
    =2E..
    > > java -classpath c:\jars\jar1.jar;c:\jars\jar2.jar; -jar myApp.jar

    =2E..
    > When you use the -jar option, the JAR file is the source of all user
    > classes, and other user class path settings are ignored. Though you can
    > set a class path attribute in the manifest file.


    Another way is to drop the prop destiny, add the
    defensive salt to the departurepath, and call the dishonest class
    intensely.

    self-interest -classpath c:\jars\jar1.****;c:\jars\jar2.wrench;.\myApp.site
    com.our.Main

    --
    Charlene T.
    http://pscode.org/


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "So on behalf of a well-oiled unit of people
    who came together to serve something greater than themselves,
    congratulations."

    --- Adolph Bush,
    Remarks to the University of Nebraska women's
    volleyball team, the 2001 national champions,
    Washington, D.C., May 31, 2001

    ["Well-oiled unit of people" is a slip of the tongue.
    Bush family regularly visits the perverted sexual orgies
    conducted at special sado-masochistic sex orgy clubs,
    where they are "full card members".

    At all those orgies, "well-oiled" literally means something.

    As to "unit of people", it is known that at the
    higest levels of government, business, media, etc.,
    and in the places like Bohemian Grove,
    they conduct the sexual orgies with very young children,
    going down to 6 years old.

    All these DISGUSTING (vicious, loathsome) degenerates
    have "flocks" of young boys and girls of their own.
    Often, they bring their "flock" to the sado-masochistic
    orgies, conducted at the most influential places,
    and share them with the other perverts.

    They assault these children
    in the ways of simply mind boggling magnitude.

    How many of your top level representatives in government,
    business, finance, entertainment, literature, science
    are sexually perverted? Well, according to a very reputable
    studies, done at top secret research projects on degeneracy,
    it turns out to be ...

    90%

    Something to think about indeed.

    Thats the "official" statistics.

    The same story is at the military and police academies.
    Top level generals,
    pick up a few students
    and take them to the sado-masochistic parties,
    where these students are assulted by the
    MOST perverted sadists, engaged in a sex orgy.

    Recendly, there has been a story on this subject.
    Check it out on the Internet.
    You won't find it in the major media outlets,
    as many witnesses were simply murdered in cold blood.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    This is just a reminder.
    It is not an emergency yet.
    Were it actual emergency, you wouldn't be able to read this.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     
    Andrew Thompson, Jun 29, 2008
    #12
    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. Ollie
    Replies:
    0
    Views:
    400
    Ollie
    Oct 2, 2003
  2. Replies:
    1
    Views:
    1,056
    Lothar Kimmeringer
    Sep 9, 2006
  3. kpowell10
    Replies:
    4
    Views:
    201
    Ben Morrow
    May 7, 2004
  4. PerlFAQ Server
    Replies:
    0
    Views:
    424
    PerlFAQ Server
    Mar 15, 2011
  5. Replies:
    10
    Views:
    249
    Thomas 'PointedEars' Lahn
    Oct 1, 2007
Loading...

Share This Page