File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I run a jar file from the terminal?

 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
having a hard time Im using Eclipse 32bit with Ubuntu 12.10 and I am not able to run a jar file in the terminal. I have exported the jar file to my documents folder, created a Manifest.txt file and I need a main-method in my class file - public static void main(String args[]){ ... } - not exactly sure hpw to check this and see what I need to change to make this work. Can anyone offer some advice? I have a few error reports that call this a fatal exception in java where there is no -vm or the eclipse file is not using the right version of java,
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hugh. Welcome to the ranch. First of all, you can execute only executable jar files. Most jar files contain packaged classes which are required to be referred to by the application. Kind of libraries. They don't run directly. What exactly does this jar file that you are trying to run contain? What all classes and what are the contents of the Manifest.txt?
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Hi Hugh. Welcome to the ranch. First of all, you can execute only executable jar files. Most jar files contain packaged classes which are required to be referred to by the application. Kind of libraries. They don't run directly. What exactly does this jar file that you are trying to run contain? What all classes and what are the contents of the Manifest.txt?

HI and its nice to be welcome! Its a simple 'hello world' that I am trying to run so that eventually I can use my IDE to build applications for java. Im pretty green at this and was doing pretty good until I had to export the file so I could run it in an external environment. here is the Manifest.txt I wrote

Main-Class: lightning.java.hello.MyFirstClass

the jar file is in the Documents folder and I placed the Manifest.txt file in the same directory.. been at this one for a while.... hopefully you can help .
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the jar file is in the Documents folder and I placed the Manifest.txt file in the same directory..


When you wrote the standalone main() class that prints "hello world", how did you convert that to a jar file?
 
K. Tsang
Bartender
Pie
Posts: 3228
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the jar has this manifest.txt file in it? Also the manifest file need an extra empty line at the end.
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Does the jar has this manifest.txt file in it? Also the manifest file need an extra empty line at the end.
yes I put a carraige return and no it is not in the the jar file, yet. Will try this
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Does the jar has this manifest.txt file in it? Also the manifest file need an extra empty line at the end.
Using the Eclipse IDE I exported it by using the drop down menu
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the Eclipse IDE I exported it by using the drop down menu

Do this exercise without eclipse or any IDE help:

a) Create a basic source file that prints "HelloWorld" and compile it.

b) Create a Manifest.txt file in the same folder. It should have an entry saying Main-Class: <classname> Remember to enter a line feed otherwise there would be a parsing exception.

c) Now fir the jar command like this: jar -cvfm MyJar.jar Manifest.txt <classname>

d) Run using java -jar <Jar file name>.jar command.

As a novice, never use an IDE. It hides the working of a command and you would not learn how things work.

 
Criselda Clave
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try to find the code.. but i can't see..
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try to find the code.. but i can't see..


You tried to find what code? And what can't you see?
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Using the Eclipse IDE I exported it by using the drop down menu

Do this exercise without eclipse or any IDE help:

a) Create a basic source file that prints "HelloWorld" and compile it.

b) Create a Manifest.txt file in the same folder. It should have an entry saying Main-Class: <classname> Remember to enter a line feed otherwise there would be a parsing exception.

c) Now fir the jar command like this: jar -cvfm MyJar.jar Manifest.txt <classname>

d) Run using java -jar <Jar file name>.jar command.

As a novice, never use an IDE. It hides the working of a command and you would not learn how things work.


Ok I will do the best I can with it. I wish I knew earlier not to use the IDE because it has cost me alot of time learning it and getting it configured right. What I would really like is a good tutorial so I can learn it from the ground up
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good tutorial eh? Only for Jars in Java, running etc. or for Java language as a whole?
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hugh Manchu wrote:
K. Tsang wrote:Does the jar has this manifest.txt file in it? Also the manifest file need an extra empty line at the end.
Using the Eclipse IDE I exported it by using the drop down menu
I tried to move the Manifest.txt into the temp.jar folder and i get an error , "cant move an archive into an archive"
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to move the Manifest.txt into the temp.jar folder and i get an error , "cant move an archive into an archive"


First of all, temp.jar is not a folder. It is a file. You cannot directly place a .txt file inside a jar. Are you following the steps I mentioned? Follow those and then let me know what is the problem.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tutorial. You probably won’t need the whole of that section.
 
K. Tsang
Bartender
Pie
Posts: 3228
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Further to what Campbell's tutorial link, here is another one just the jar command here

Pay attention to the available options or flags. Also check out the examples too at the bottom.
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Using the Eclipse IDE I exported it by using the drop down menu

Do this exercise without eclipse or any IDE help:

a) Create a basic source file that prints "HelloWorld" and compile it.

b) Create a Manifest.txt file in the same folder. It should have an entry saying Main-Class: <classname> Remember to enter a line feed otherwise there would be a parsing exception.

c) Now fir the jar command like this: jar -cvfm MyJar.jar Manifest.txt <classname>

d) Run using java -jar <Jar file name>.jar command.

As a novice, never use an IDE. It hides the working of a command and you would not learn how things work.



I have never written any java before and Im not familiar with the layout that well, nor do I know all the things I will need to make a src file run from scratch. I am doing a tutorial that uses Eclipse IDE so instead of re learning everything I think for the sake of time management I should try to work with the IDE to resolve this. It doesnt seem to be a huge issue from a users perspective as I managed to get some good answers at other boards however the problem from looking at it for a few days seems to be the way that the jre 6 is configured inside Eclipse. This is the nature of my question and this is what i have discovered after days of looking for solutions. I have a simple"Hello World" including the src file, manifest files and jar file ready to go in the IDE I mentioned. I came to this forum to get some friendly help about configuring jre 6 in eclipse and solving the runnable jar problem that exists
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:A good tutorial eh? Only for Jars in Java, running etc. or for Java language as a whole?

I am going to use the Lars Vogella tutorial I have which is the best choice for me at the moment.
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Tutorial. You probably won’t need the whole of that section.

Ok just go this will have a look at this right away sheriff.. Thanks
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Further to what Campbell's tutorial link, here is another one just the jar command here

Pay attention to the available options or flags. Also check out the examples too at the bottom.

Ok will do this .Thanks alot. I have encountered errors in the IDE and can set the vogella tutorial for eclipse aside for a bit
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
I tried to move the Manifest.txt into the temp.jar folder and i get an error , "cant move an archive into an archive"


First of all, temp.jar is not a folder. It is a file. You cannot directly place a .txt file inside a jar. Are you following the steps I mentioned? Follow those and then let me know what is the problem.

I have some better resources available to me now so I will let you know if I have any troubles when the time comes to test this out. For now Im going to look at this very closely without the use of the IDE and get back to you once I have some results.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good idea. And good luck with it
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks awesome from what ive seen thus far. Whats the deal with javaFX? is it something I can use to manage and render some of this code? If so can I get it from the command prompt in Ubuntu?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaFX Tutorial.
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
crashing? cant render that tutorial
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some better resources available to me now so I will let you know if I have any troubles when the time comes to test this out. For now Im going to look at this very closely without the use of the IDE and get back to you once I have some results.


Sure thing Hugh. Always there for assistance.
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
btw .. the problem I had has been resolved.. I had an error in my manifest.txt that went unnoticed. Everything seems to be running s smoothly now. Thanks for your help everyone
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hugh Manchu wrote:crashing? cant render that tutorial
Try http://docs.oracle.com/javafx/tutorials.html
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... or the more modern http://docs.oracle.com/javafx/index.html
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Didn’t realise that tutorial was out of date.
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
success.
Screenshot from 2013-03-11 13:36:17.png
victory is mine
[Thumbnail for Screenshot from 2013-03-11 13:36:17.png]
 
Hugh Manchu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im a thinkin Im gonna go mozy on down and do some yip-yappin with the buckaroos o'er yonder at that bunkhouse thread you be callin java mobile edition, as that is the stagecoach I be expectin to catch, yippie kaye yay
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic