• 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

How to execute the jar file from command prompt?

 
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello people. I have 3 sub directories(out,res, src) in my root folder(first project). I created a jar file using command After that first.jar is created successfully. But when i run the jar file using I'm getting an error saying that class not found. I have checked the manifest file and the class com.project.test.EmployeeTest is present. So, where I'm going wrong? or do you need more information?
3.JPG
[Thumbnail for 3.JPG]
 
Saloon Keeper
Posts: 15490
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Packages need to be at the root of the JAR.

If you have resource packages in the res/ folder, you will first need to copy them to your out/ folder, so that the packages are merged.
You could write a batch file, which under Windows would look something like this:

 
Rajeev Srikhar
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But now i got new error
5.JPG
[Thumbnail for 5.JPG]
 
Stephan van Hulst
Saloon Keeper
Posts: 15490
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the entire command you used?
 
Rajeev Srikhar
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my code
1.JPG
[Thumbnail for 1.JPG]
 
Stephan van Hulst
Saloon Keeper
Posts: 15490
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you didn't actually specify which files you want to add. That's why my example command has a dot at the end.
 
Rajeev Srikhar
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got output now. Thank you. The dot(.) specifies to add all the files in the current directory ,right? and Is there any way to execute the jar file without using that copy command i.e something like keeping jar -cfe first.jar com.project.test.EmployeeTest -C out res .
 
Stephan van Hulst
Saloon Keeper
Posts: 15490
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not if you need the resources to be on the classpath. If you want the resources to be in a separate folder within the JAR you can just add it directly, but then you won't be able to reach them using the getResource() and getResourceAsStream() methods, unless you prefix all the resource names with the name of the folder, which is bad form.

Let's say you have a class com.example.Hello, and you have a resource res/com/example/hello.txt. You can perform the following command:

This will create a JAR with the com/ folder at the top, and the res/ folder at the top. The problem with this approach is that to access the resource from your code, you have to call getResourceAsStream("/res/com/example/hello.txt") instead of the more sensible getResourceAsStream("hello.txt").
 
Rajeev Srikhar
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for elaborate answer. Now, its time for me to explore more.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic