PDA

View Full Version : Shorthand java compiliation/run



arod529
April 1st, 2009, 04:28 AM
So I have java jdk on my linux box.

Instead of using Terminal to compile and run my programs I created custom app. launchers. For compiliation I just pointed to /usr/local/jdk1.6.0_12/bin/javac. Works great. I did the same for running the program(pointed to /usr/local/jdk1.6.0_12/bin/java).

Problem: the java command uses the .class file name without the .class extention. Is there anyway to make the custom application launcher truncate the .class file extention?

Also doing the same(/usr/local/jdk1.6.0_12/bin/javadoc) for javadoc creates the documentation files in my /home/<username> folder even though the .java file is on my desktop. Wierd.

Thanks for the help.

CptPicard
April 1st, 2009, 05:48 AM
IMO the correct way to approach automating Java project builds, tests etc on the command line is to write an ant script :)

arod529
April 3rd, 2009, 09:53 PM
I have no idea how to use ant script. I found this web page http://mindprod.com/jgloss/ant.html (http://mindprod.com/jgloss/ant.html), but it looks like its alot more compicated than I'm looking for. As of right now, the only thing I am doing is compiling .java files. I don't do anyting with .jar files and the like.

Reason: I'm taking a beggining java class at the community collage.

If you can explain how to write and use the appropriate ant script, I'd be happy to learn.

myrtle1908
April 4th, 2009, 01:02 AM
So I have java jdk on my linux box.

Instead of using Terminal to compile and run my programs I created custom app. launchers. For compiliation I just pointed to /usr/local/jdk1.6.0_12/bin/javac. Works great. I did the same for running the program(pointed to /usr/local/jdk1.6.0_12/bin/java).

Problem: the java command uses the .class file name without the .class extention. Is there anyway to make the custom application launcher truncate the .class file extention?

Also doing the same(/usr/local/jdk1.6.0_12/bin/javadoc) for javadoc creates the documentation files in my /home/<username> folder even though the .java file is on my desktop. Wierd.

Thanks for the help.

What language is your "launchers" app written in? It is simple to remove parts of string eg. '.class' but need to know what you are using. For example, in Perl you could write ...


my $class_file = 'abc.123.class';
$class_file =~ s/\.class$//i;
print $class_file;

Which would print: 'abc.123'.

arod529
April 8th, 2009, 02:00 AM
What language is your "launchers" app written in? It is simple to remove parts of string eg. '.class' but need to know what you are using. For example, in Perl you could write ...


my $class_file = 'abc.123.class';
$class_file =~ s/\.class$//i;
print $class_file;

Which would print: 'abc.123'.

I'm not using a language.

Here is what I did:
Right click the file and click open with. At the bottom of the window click on the arrow next to custom command. Click browse and point to /home/usr/local/jdk<version number>/bin/javac. Obvoiusly you replace javac with whatever command you wish to run.

The Cog
April 8th, 2009, 11:30 PM
You might be able to do something with the program basename. Just a guess, but perhaps put in the launcher:

java $(basename $1 .class)

but can I suggest you install geany - a nice syntax-highlighting editor with a compile button and error highlighting.

arod529
April 11th, 2009, 07:29 PM
Well, for some reason I couldn't get the basename keyword to work with the program launcher. But I conveintly discovered the External Tools plugin and can compile, run, and document my files all with a button. I basically turned gedit into a super simplistic IDE.

The only thing is it doesn't check whether the file has been changed so make sure the file is saved before running the javac command.

Even though any errors are not highlighted the comiler tells you what line they are on. With the line numbers enabled debugging isn't any harder(for comilation errors) than in an IDE.

The screenshots got kinda screwed unless you press the "Expand" button that appears when you hover over the picture.

By the way, I did try geany but the compiler and run commands wouldn't work. It gave me some weired error. I don't remmember what is was though. Besides, I absoulutly love the snippets plugin for gedit.