LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 02-04-2012, 12:03 AM   #1
OmegaD
LQ Newbie
 
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11

Rep: Reputation: 0
Unhappy 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.
 
Old 02-04-2012, 12:27 AM   #2
rahulkya
Member
 
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 186
Blog Entries: 3

Rep: Reputation: 33
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
 
Old 02-04-2012, 12:46 AM   #3
OmegaD
LQ Newbie
 
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11

Original Poster
Rep: Reputation: 0
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?
 
Old 02-04-2012, 02:18 AM   #4
OmegaD
LQ Newbie
 
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11

Original Poster
Rep: Reputation: 0
Lightbulb 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!
 
Old 02-04-2012, 05:30 AM   #5
rahulkya
Member
 
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 186
Blog Entries: 3

Rep: Reputation: 33
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"...
 
Old 02-04-2012, 08:16 PM   #6
OmegaD
LQ Newbie
 
Registered: Dec 2010
Distribution: LMDE Xfce 64
Posts: 11

Original Poster
Rep: Reputation: 0
:/

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.
 
  


Reply

Tags
command, java, launcher, terminal


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we create a text Based Menu for complex Linux Operations k41184 Linux - Software 15 04-27-2014 12:49 AM
How to create a launcher for a Java application ratilio Linux - Newbie 8 06-30-2010 03:59 PM
New Software: Curses-Based Program Launcher CoderMan Linux - Software 8 07-17-2009 08:36 AM
Does Red Hat have a text based admin program? OOsorio Linux - Newbie 3 05-07-2008 10:18 PM
Create Gnome Desktop Icon, Program Launcher qwerty_tele Linux - Newbie 10 02-09-2008 11:07 PM


All times are GMT -5. The time now is 03:57 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration