• 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Difficulty with JARs and classpaths

 
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I've written an application which uses two other JAR files, and am trying to package it into a JAR file - something that I've never done before... I am having considerable difficulty with classpaths and where to put the various JAR files. Ideally, I would like to have the two JAR files I've used inside the JAR file for my application, but I'm not sure that my classes will be able to reference the classes within them if I do this, without custom code (this is what the documentation seems to suggest, but I may have misunderstood it). I have compiled my java files using -classpath <absolute reference to the directory in which they are stored>, which could possibly be why it isn't working now that I've moved the JARs? I don't mind just putting my application's JAR archive file in the same folder as the other two I am using - I have tried this and adjusted the Class-Path field in the manifest.mf file but with no success.

Would anybody be able to advise me on how to compile my java code (i.e. regarding the classpath), where relative to each other in the directory structure I should put my various class and JAR files, and what the manifest.mf file should contain in order to make it work?

Any help would be very much appreciated :/ Thanks!
 
Master Rancher
Posts: 4460
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

putting my application's JAR archive file in the same folder as the other two I am using - I have tried this and adjusted the Class-Path field in the manifest.mf file but with no success.  


That should work.
What error messages do you get when you open a command prompt window in the folder with the 3 jar files and enter:
java -jar <YOURJARFILENAME>.jar

Copy the contents of the command prompt window and paste it here.
 
F Turner
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Norm,

The program starts running fine, but then I get this:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/json/stream/JsonParsingException
       at MainClass.main(MainClass.java:323)
Caused by: java.lang.ClassNotFoundException: javax.json.stream.JsonParsingException
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 1 more
 
Norm Radder
Master Rancher
Posts: 4460
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the  javax/json/stream/JsonParsingException  class?
Is it in one of the 3 jar files?
What is the contents of the Class-Path: line in the manifest file in the jar file?

What version of the java command are you using?
 
F Turner
Ranch Hand
Posts: 31
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, apologies for my delayed reply.

Yes, the JsonParsingException class is in one of the other JAR files (not the one which contains my application).

I have just managed to get it working - I opened the manifest file after extracting it so that I could post its contents, and the JAR files listed in the Class-Path: line were missing the extension .jar; I had found this before and thought I had added it, but obviously passed the jar command to create the jar the old manifest file.

In case it makes a difference, I also put the two JARs which I am using in the same folder as the source code when compiling it, so that in the -classpath argument to javac I only needed to give the names of said JAR files and not absolute file paths - would this have made a difference?

Thanks for the help - if you hadn't made me re-open the manifest file I wouldn't have found the problem :P
 
I think she's lovely. It's this tiny ad that called her crazy:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic