Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-04-2012, 12:03 AM
|
#1
|
|
LQ Newbie
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11
Rep:
|
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.
|
|
|
|
02-04-2012, 12:27 AM
|
#2
|
|
Member
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 185
Rep:
|
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
Now you can double click to run this program/jar
|
|
|
|
02-04-2012, 12:46 AM
|
#3
|
|
LQ Newbie
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11
Original Poster
Rep:
|
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?
|
|
|
|
02-04-2012, 02:18 AM
|
#4
|
|
LQ Newbie
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11
Original Poster
Rep:
|
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:
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:
You can test your bash file to make sure it's functional by opening a terminal and typing:
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":
Pick a cool icon & hit "create" and you're done! You now have a double-click-able icon for your "Hello World" Java program!
|
|
|
|
02-04-2012, 05:30 AM
|
#5
|
|
Member
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 185
Rep:
|
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"...
|
|
|
|
02-04-2012, 08:16 PM
|
#6
|
|
LQ Newbie
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11
Original Poster
Rep:
|
:/
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:01 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|