• 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

cp not being recognised

 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have added a jar file to my classpath and compiled a class that refers to a class in that jar file. It compiles fine. I have added the jar file to the system classpath too. When I run the code, I get a at the line that java.lang.NoClassDefFoundError exception. I println the java.class.path property just before this line and the jar file is in my classpath. So, if a jar file is in the classpath and the path is correct, what else can cause this exception? Could it be a security thing?
Thanks for an help.
Paul
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class (or package) could be mis-named. This probably isn't it because you could compile. But I have seen things like this when I renamed a class or package and ended up with both old and new named versions hanging around - maybe one version didn't make the jar.
Or maybe the jar has the wrong path in it. If your package starts with "com.foo" then the stuff in the jar should be "com/foo". Look at the output of jar tf ....
Or maybe you have the FiLeNaMe case incorrect. If you are on Windoze, then the filesystem doesn't care so java gives you some slack. But once you stick the thing in the jar if the NaMe in the jar doesn't match the Name of the class it probably won't find it at runtime.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of these things seem to be okay. Here's the error I get and I println the classpath right before I try to look at the class.
Classpath = c:\APP_FILES\app_1.1.2\lib\mon.jar;c:\Java\jdk1.3.1_04\jre\lib\rt.jar;c:\Java\jdk
1.3.1_04\jre\lib\i18n.jar

My error -
java.lang.NoClassDefFoundError: com/thro/lis/app/Cell
at com.ibm.sns.svk.qik.KeypadWindow.KeypadChanged(KeypadWindow.java:296)
at com.ibm.sns.svk.qik.VipThread.run(VipThread.java:202)
at java.lang.Thread.run(Thread.java:479)


There is a Cell interface in the mon.jar file in the same directory as shown in the classpath above. When I load it into Winzip and check its path it is com/thro/lis/app whic looks right to me.
So what else could trigger a NoClassDefFoundError?
Thanks.
Paul
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checking into this more, I've found that I can access static methods on this 'missing' class but I get the NoClassDefFoundError when I try to do an instanceof on it.
Why would this be?
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Me again responding to myself. I've looked through a lot of stuff to find the answer to this problem. Most answers seem to say, just because you have your classpaths and all set correctly does not mean the class can actually be 'seen' at runtime - even if it is seen at compile time.
I haven't yet seen any description of what to do to fix it. My classpath contains the jar file with this class in it. Is it possible that System.getProperty("java.class.path") can actually show up a different classpath than the one being used?
Paul
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried specifying a classpath when running the application.
For instance
javac -classpath="path to your jar" MyApp.class
I have noticed that sometimes javac doesn't work correctly with a classpath set in the enviornment variables.
Another option is to unjar the jar file, and then jar up the jar file along with your application. Then, since the libraries are all there together, you should'nt run into this problem. (Hopefully). Just another option I supose. Probably not ideal.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response Gregg.
I am running the application and setting the classpath at the same time but it doesn't seem to make a difference. What's confusing me is that when I write the classpath directly before I reference the class, the correct jar file is in there. I use the System.getProperty("java.class.path") method to do this. It looks like this may not be the real classpath at the time - at least that's my conclusion so far.
I've thought about loading all the classes I want into my own jar file but it's something I really want to avoid.
Paul
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can think of several possibilities....
Since you can call static methods on the class, you know the class can be loaded - at least from the code where you are calling static methods. Try creating a new instance right there and see what you get. If it works, won't tell you much. If it doesn't maybe you can track down why in a smaller set of code.
I have seen NoClassDef or similar being thrown when a static initializer (or assignments to static variables) threw a Runtime or Error. Usually, this involved a combination of reflection and other stuff that just confused the VM. It couldn't load the class because of the failures so it thres a NoClassDef or something like it. This is unlikely since you can call methods on the class.
I notice your code is in "com.thro...." package but is being called by "com.ibm.sns...." something. I assume you are plugging into some ibm framework for something. Do you know what they're doing in there (how they're trying to instantiate the class)? For example, maybe it's:

Not likely, but if they do something like that, it'd really mess with your head.
Another possibility is that the com.ibm.sns... stuff is creating its own ClassLoader to load these classes and thus its not even looking in your CLASSPATH....
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried with a .(dot) in the CLASSPATH?
Rene
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul Keohan,
You can try setting the classpath in the console.
Use the following command and execute that twice if need be. Because in java some times the classpath is not setting properly.

set classpath=.;c:\APP_FILES\app_1.1.2\lib\mon.jar;%classpath%

I think this will work.
Cheers,
Vasu.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic