LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Want to create launcher for text-based Java program (http://www.linuxquestions.org/questions/linux-newbie-8/want-to-create-launcher-for-text-based-java-program-927510/)

OmegaD 02-04-2012 12:03 AM

Want to create launcher for text-based Java program
 
I wrote a text-based Java program in Eclipse, which I normally run in the Console within Eclipse. But that's a lot of system resources for running a rinky dink program.

I can open a Terminal and type "java <filename>" and run it in the Terminal, but what I would really like is a launcher.

I tried to create a new launcher, enter "java <filename>" next to "Command:", and "/home/<...directory>" next to "Working Directory:", and check the box next to "Run in terminal". When I tried opening it, the terminal flashes on the screen and immediately disappears.

What I would like to do is have an icon on my desktop that I can double-click and have it open a Terminal, "java <filename>" the program, and then remain open so I can interact with it. How can I accomplish this?

Btw, I also tried making a jar file out of my 2 class files, but I had no idea what I was doing, and it obviously didn't work.

rahulkya 02-04-2012 12:27 AM

although this question should be in a java forum I give you a solution.
Here are the steps..
1. Put your .class files in a folder
2. create a file manifest.txt in that folder and type
Quote:

Main-Class: ClassNameContainigMainMethod
this line inside that file and this line should end with a return{enter key}
3. then create a jar with this command{cd to go to above folder by terminal}
Quote:

jar cvfm MyExecJar.jar manifest.txt *.class
4. make this jar executable by the command
Quote:

chmod +x MyExecJar.jar
Now you can double click to run this program/jar

OmegaD 02-04-2012 12:46 AM

Missing something
 
I was successful in creating the jar file.

However, after entering the chmod command, when I double-click the jar file, it just shows the content of the jar file (I don't think it converted to an executable.)

I tried making a launcher to run the jar file (again), but still no luck.

Any ideas?

OmegaD 02-04-2012 02:18 AM

Eureka!
 
I got it! Here's the solution:

First, you can use Eclipse to create a jar file if you're like me and prone to making noob mistakes. Here's how... in Eclipse, right-click the package, Export, JAR file, next, type in destination folder, next, next, Browse for Main Class, Finish. You can test your jar file to make sure it's functional by opening a terminal and typing:
Quote:

java -jar <filename>.jar
Once you have a functional jar file, go to your home folder and create a new empty file called "runit" or something, with no extension. Open it and enter the following:

Quote:

#!/bin/bash
java -jar "/<full path>/<filename>.jar"
Make sure to include the quotation marks, and then save it. Now make it an executable bash file by opening a terminal and typing:
Quote:

chmod a+x runit
You can test your bash file to make sure it's functional by opening a terminal and typing:
Quote:

./runit
Now create a new launcher by right-clicking on the desktop & selecting "Create Launcher." Enter a name, check the box that says "run in terminal", and enter the following next to "Command":
Quote:

./runit
Pick a cool icon & hit "create" and you're done! You now have a double-click-able icon for your "Hello World" Java program!

rahulkya 02-04-2012 05:30 AM

Good one ...But if you want to run jar itself(double clicking) not by Bash.
change the file opening option
right click on file(.jar file) go to properties>go to open with and then choose open with "OpenJDK runtime Environment"...

OmegaD 02-04-2012 08:16 PM

:/
 
That did not work for me... perhaps because this particular program needs to run in a terminal. (Or I might need more detailed instructions.)

I'll stick with the bash launcher - that worked well.


All times are GMT -5. The time now is 11:22 AM.