File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How do I run a jar file from the terminal? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I run a jar file from the terminal?" Watch "How do I run a jar file from the terminal?" New topic
Author

How do I run a jar file from the terminal?

Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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

Joined: Jul 27, 2010
Posts: 1157

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?


~ Mansukh
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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

Joined: Jul 27, 2010
Posts: 1157

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

Joined: Sep 13, 2007
Posts: 2229
    
    7

Does the jar has this manifest.txt file in it? Also the manifest file need an extra empty line at the end.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Jul 27, 2010
Posts: 1157

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

Joined: Mar 07, 2013
Posts: 6
i try to find the code.. but i can't see..
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Jul 27, 2010
Posts: 1157

A good tutorial eh? Only for Jars in Java, running etc. or for Java language as a whole?
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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

Joined: Jul 27, 2010
Posts: 1157

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

Joined: Oct 13, 2005
Posts: 37907
    
  22
Tutorial. You probably won’t need the whole of that section.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Oct 13, 2005
Posts: 37907
    
  22
You’re welcome
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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

Joined: Oct 13, 2005
Posts: 37907
    
  22
Good idea. And good luck with it
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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

Joined: Oct 13, 2005
Posts: 37907
    
  22
JavaFX Tutorial.
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
crashing? cant render that tutorial
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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

Joined: Mar 08, 2013
Posts: 16
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

Joined: Oct 13, 2005
Posts: 37907
    
  22
Hugh Manchu wrote:crashing? cant render that tutorial
Try http://docs.oracle.com/javafx/tutorials.html
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

... or the more modern http://docs.oracle.com/javafx/index.html


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37907
    
  22
Thank you. Didn’t realise that tutorial was out of date.
Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
success.



[Thumbnail for Screenshot from 2013-03-11 13:36:17.png]

Hugh Manchu
Greenhorn

Joined: Mar 08, 2013
Posts: 16
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
 
wood burning stoves
 
subject: How do I run a jar file from the terminal?
 
Similar Threads
Running a runnable jar File
Create Executable Jar File With User Library
Java Environment Setup Problem - OS X 10.4.3, Java 1.5.0 - Running from Terminal
Run class file using Terminal on Mac Leopard
How to create a jar file of a java project that uses Derby database