HOWTO: Set gedit to compile and run Java source code

Introduction

I use gedit with the terminal panel plugin when I'm programming small Java programs. This becomes a hassle sometimes, so I created a simple gedit "Tool" that would compile and run Java source files. Some people would prefer using just the plain terminal or a complicated IDE, but this is especially useful for students who just needs a basic yet easy-to-use interface to learn Java on.

Instructions

First, open gedit and go to Tools=>External Tools. Create a new tool and label it something like "Java Compile." Set an accelerator if you want to.

The second part (the tool to run the class) is a bit more difficult because gedit runs the script using /bin/sh, which doesn't support the necessary regex command. Because of this, we have to make a separate script file.

Re: HOWTO: Set gedit to compile and run Java source code

Hi,

I'm a beginning java programmer (in two days I have my exam) and I use eclipse by default as editor and compiler.
However I want to compile and run my java programs also in gedit, because I love the simplicity of gedit and for a fast check, gedit is excellent...
So I found this thread and I am able to compile without any problem, however, running the program just doesn't seem to work out!
This is what I get:

Re: HOWTO: Set gedit to compile and run Java source code

Here is a script for compiling and running a java program. I ran into the problem of having to set the class path, my script does this for you. Also, you have to have python installed for this to work.

it works for my purposes. There is just one case that i can see that this wont work on, if you have something like this. my script will see the other package statement there and think it is the one we need.

Code:

/*
this is the old package
package something.another.and.another;
*/
package something.else.in.another.place;

that being the case, the following would work fine

Code:

//this is the old package
//package something.another.and.another;
package something.else.in.another.place;

Re: HOWTO: Set gedit to compile and run Java source code

I had several issues here:

1) The following error occured when I import java.util.* to called the Scanner.

Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:855)
at java.util.Scanner.next(Scanner.java:1478)
at java.util.Scanner.nextInt(Scanner.java:2108)
at java.util.Scanner.nextInt(Scanner.java:2067)
at Q8.main(Q8.java:32)

Exited: 256

2) If the .java file is located on another drive, eg: /media/WINXP/Documents and Settings/UserName/My Documents/My Java, the following error will occured. But still, it will still run the .class file.