• Post Reply Bookmark Topic Watch Topic
  • New Topic

Executable jar file not running  RSS feed

 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there fellow programmers!I recently finished a small Rock Paper Scissors game with the help of two amazing guys on this forum and i wanted to export it as a runnable file.I exported the executable jar file but when i double click it,nothing happens.I also tried running it from the cmd but nothing happens.
Also used Launch4j to convert it into  a .exe file but still nothing.How can i find what the issue is?Thanks in advance ;) !
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tried running it from the cmd but nothing happens. 

Can you try to execute it in a command prompt window and copy the full text of the window and paste it here to show what happens?
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I exported the executable jar file

How did you do this?  Maven, Eclipse?
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:
I exported the executable jar file

How did you do this?  Maven, Eclipse?


For the executable jar file i used eclipse and then for the .exe one i used Launch4j like i siad !
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
tried running it from the cmd but nothing happens. 

Can you try to execute it in a command prompt window and copy the full text of the window and paste it here to show what happens?

That's my problem,i execute it,and nothing pops up it's like if it has already run and finished without logging anything into the console!
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finished without logging anything into the console!

If nothing was written to the console, that would mean the program executed without any exceptions and exited without doing what you want.  Try adding some print statements in the program to show the program's execution trail.  Then when you execute the code in the jarfile, the print outs from those print statements will show you where the program was executing.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stelios papamichael wrote:That's my problem,i execute it,and nothing pops up it's like if it has already run and finished without logging anything into the console!


And did you execute it as "java -cp yourapp.jar appsmainclass" or "java -jar yourapp.jar" or "javaw -cp yourapp.jar appsmainclass" or what? Some of those varieties display a console and some don't. It looks like you chose one which doesn't.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would really help if you copied the full contents of the command prompt window from when you execute it so we can see what is displayed or not displayed.

There is important information there we need to see.


For example this is what I see with a test program:

D:\JavaDevelopment\Testing\ForumQuestions11>java TestCode22

D:\JavaDevelopment\Testing\ForumQuestions11>


Is the following what you see?

D:\JavaDevelopment\Testing\ForumQuestions11>java MyGame


 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
stelios papamichael wrote:That's my problem,i execute it,and nothing pops up it's like if it has already run and finished without logging anything into the console!


And did you execute it as "java -cp yourapp.jar appsmainclass" or "java -jar yourapp.jar" or "javaw -cp yourapp.jar appsmainclass" or what? Some of those varieties display a console and some don't. It looks like you chose one which doesn't.


Alright,if i write java -jar Rock_Paper_Scissors.jar in the cmd it works like a charm.But i am still curious on why it does not run when i double click on the file itself.Through the cmd it works though!
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -jar Rock_Paper_Scissors.jar in the cmd it works

why it does not run when i double click on the file itself.

Can you post the code that you are compiling, putting in the jar and executing? 
Does the program use the console?  That will be a problem when starting the jarfile with a double click.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stelios papamichael wrote:But i am still curious on why it does not run when i double click on the file itself.


You're using Windows, right? Then you haven't configured Windows to open files of type *.jar using the java -jar command. For some reason installing Java doesn't make that change.

I used to know how to do that when I was using Windows 7, but now that I installed Windows 10 I can't find the right link. I assume it's still available... yes, it's under the Settings pages somewhere.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do something like this to specify what to do to run a jar file:

ftype jarfile="C:\Program Files\Java\jre1.8.0_45\bin\java.exe" -jar %1 %*
assoc .jar=jarfile


You can name the filetype anything which doesn't conflict what may already be configured (I used jarfile).

Change the path to java.exe to match your environment (mine is C:\Program Files\Java\jre1.8.0_45\bin\java.exe).
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before changing the Registry with the assoc and ftype commanda, try listing the filetype associations first by opening a command prompt window and entering:
assoc>assocTable.txt
That command will list all the associations in the registry.

Here are a few lines from the assocTable.txt file I just created:
.itss=MS-ITSS File
.jar=jarfile_NCR    <<<<<<<<<< I have my own name here.  The java installation would be just jarfile
.java=VisualStudio.java.8.0
.jfif=pjpegfile

Then run this command to get a list of the filetypes:
ftype>ftypeList.txt

Here are some lines from the ftypeList.txt file when I just ran the above:
InternetShortcut="C:\WINDOWS\system32\rundll32.exe" "C:\WINDOWS\system32\ieframe.dll",OpenURL %l
jarfile="C:\Program Files (x86)\Java\jre1.8.0_91\bin\javaw.exe" -jar "%1" %*
jarfile_NCR="C:\Program Files (x86)\Java\jre1.8.0_91\bin\javaw.exe" -jar "%1" %*
jfrfile="C:\Program Files\Java\jdk1.8.0_60\bin\jmc.exe" -open "%1" %*

The reason I have my own ftype entry is that I have several special commands I can access from right clicking on a jar file.  The java install completely replaces the jarfile entry so I have my own entry to preserve my special options.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
java -jar Rock_Paper_Scissors.jar in the cmd it works

why it does not run when i double click on the file itself.

Can you post the code that you are compiling, putting in the jar and executing? 
Does the program use the console?  That will be a problem when starting the jarfile with a double click.


Two classes :

MyGame :



Logic :

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code on line 19 reads from the console.  That won't work from a jarfile started without a console.
Change the code to use a JOptionPane method that shows a dialog window to read user input.

Also the println statements won't show without a console.  They need to be changed to use a JOptionPane method.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may think this is a lot of hassle just to run a simple console-based program. But the fact is that console-based programs have been basically obsolete since about 1995 and Java (having been designed after that) doesn't really care about them.

So, using a console for a user interface is a useful technique for learning basic programming. But writing a real application which uses a console in Java isn't really a practical thing to do.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:The code on line 19 reads from the console.  That won't work from a jarfile started without a console.
Change the code to use a JOptionPane method that shows a dialog window to read user input.

Also the println statements won't show without a console.  They need to be changed to use a JOptionPane method.


Any good source from which i can learn what JOptionPane method is and how to use it properly?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked in the API doc for the JOptionPane class?  Click on the link the site set for JOptionPane.
http://docs.oracle.com/javase/8/docs/api/index.html

Otherwise, do an internet search for sample code.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stelios papamichael wrote:. . . Any good source from which i can learn what JOptionPane method is and how to use it properly?
Yes. Here. Only they call it something different.

If you are going to use option panes, do you have enough experience to run the whole application from a GUI? If you don't use a GUI, try null as the first argument to the showXXX methods. That sh‍ould make the dialogue apear in the centre of the screen, but beware. I have known it appear “behind” something else, and you have to minimise windows to find the dialogue.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:. . . do you have enough experience to run the whole application from a GUI? . . .


No i do not have much experience with Java so going into this whole panes thing wouldn't be the best idea...hmmm....Any other ideas guys?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JOptionPane class methods would be the simplest way to get user input and show the program's output.
Creating a full GUI window requires a lot more java knowledge.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't quote the whole of the preceding post; that simply makes he thread longer and longer.
If you don't have enough experience to use a GUI and if you need to run your app as an executable .jar, go to the link I gave you yesterday which tells you how to get input with an option pane. That is just about the only way to get input and output in this situation, as NR suggests.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Don't quote the whole of the preceding post; that simply makes he thread longer and longer.
If you don't have enough experience to use a GUI and if you need to run your app as an executable .jar, go to the link I gave you yesterday which tells you how to get input with an option pane. That is just about the only way to get input and output in this situation, as NR suggests.


Thankfully,i found a few videos on youtube that explained JOptionPane a lot easier than the post and managed to fix the issue completely!Thanks to everyone for helping me !
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done Please tell us which you thought the best tutorial was. It might be useful for other people.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!