• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jar files

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I have a library in a jar file that has this:

10230 Mon Dec 11 00:23:48 MST 2006 com/sun/syndication/io/XmlReader.class
1692 Mon Dec 11 00:23:48 MST 2006 com/sun/syndication/io/XmlReaderException.class

I compile a program, that has this line in it:

XmlReader reader = null;

It compiles into a class with no complaints

javac -cp ./rome-0.9.jar:./jdom.jar Reader.java

However, when I run it:

java -cp . Reader

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/syndication/io/XmlReader

so is it expecting access to the jar file at run time? (I thought jar files get compiled into the class)

Thanks
Brian









 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian R Wolf wrote:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/syndication/io/XmlReader

so is it expecting access to the jar file at run time? (I thought jar files get compiled into the class)



Yes, it is expecting the jar file. (and no, it doesn't get compiled into the class).

Henry
 
Brian R Wolf
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how to do that:

java -jar ./rome-0.9.jar -cp ./Reader
Failed to load Main-Class manifest attribute from
./rome-0.9.jar

Thanks
Brian
 
Brian R Wolf
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also try this

java -cp ./rome-0.9.jar ./Reader
Exception in thread "main" java.lang.NoClassDefFoundError: //Reader
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian R Wolf wrote:I'm not sure how to do that:

java -jar ./rome-0.9.jar -cp ./Reader
Failed to load Main-Class manifest attribute from
./rome-0.9.jar




The -jar option is to run specially configured jar files -- that specifies a main. To run a class, that needs a jar just include the jar in the class path. In much the same way as you did while compiling....

java -cp ./rome-0.9.jar:. Reader


Henry
 
Brian R Wolf
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, that works great , thanks
one more thing bugging me about jar files,

I have this one

jar xvf twitter4j-core-2.1.0.jar

....

and clearly contains
inflated: twitter4j/http/HttpClient.class

however when I try to use this class,

I declare it in the program:
....
import twitter4j.internal.http.HttpClient;
....

then when I try to compile:

javac -cp ./twitter4j-core-2.1.0.jar FeedMonitor.java

FeedMonitor.java:133: cannot find symbol
symbol : class HttpClient
location: class FeedMonitor
private HttpClient http = new HttpClient();




 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because those two classes are two different classes -- as a classname is fully qualified with the package too. The class you are trying to import is not the one in the Jar file.

Also, unless you are sure, I don't recommending changing the import -- just because two APIs have the similar class names doesn't mean that they work the same.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic