[SOLVED] Want to create launcher for text-based Java program
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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}
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.
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:
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!
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"...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.