• 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

Problem in executing java project jar file

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

I could not able to run java main class properly. This is how I do;

I have a java project created in eclipse, say Abc. Project has build path to external jar files. I created the jar file Abc.jar, exported from eclipse.
So inside the jar file I have lib folder in which the external jar files(ExtJar.jar) are stored.
I went to that folder through command prompt, and tried to run the java class. like:

java -cp Abc.jar com.javalabs.examples.Abc

But it says, class not found; that class belongs to external jar ExtJar.jar file.

As an alternative trail, I tried : java -cp Abc.jar;lib\ExtJar.jar com.javalabs.examples.Abc

The package structure and folder structure are correct.

So how can I set the path for the external jar files???

I hope my doubt is asked clearly.

Any and all suggestions are appreciated. Also let me know in case of any confusion in the question.

Thanks and Regards.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you use a manifest file? Or specify the main class when creating the jar file? I recommend using manifest file.



Since you are using external jar files, you need to specify the class path in the manifest file as well. Then to create the jar
"jar cvfm abc.jar manifest.txt lib -C classes . " The lib directory is included. The -C flag change directory to classes and add all those files/folders to the jar. The classes directory is just where all the *.class files are.

Hope this helps.
 
Shake Sajan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, thank you for response.

Since I am using eclipse for creating the jar file, I could not find any option to include the referred resources or jar files explicitly.
And Manifest.mf file is inside the jar file, I am not able to edit it.
I thought, since using eclipse, the required resources and jar file path would be added into the manifest by the eclipse ide.

So what you think, how can I resolve this issue?
 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Fat Jar plug-in for creating the jar files.
 
reply
    Bookmark Topic Watch Topic
  • New Topic