Question

Is there a way to compile and execute java files using one command, say F1, in Geany?

Its much more comfortable than having to click f5 to wait for the class to compile first, then F1 to execute that compiled file.

Was it helpful?

Solution 2

You could try creating a shell script that first compiles the class and then runs it. Then set up this shell script instead of pointing Geany to javac and java respectively.

On the downside, you will have to handle compilation failures in the script, which sounds ugly.

I would recommend to stick with the existing workflow in Geany.

If you're looking for advanced functionality, you might want to consider upgrading to a real IDE like Eclipse or Netbeans.

OTHER TIPS

Yes you can!

While editing a Java file, go to Build > Set Build Commands. Under Java commands click the first empty label and give it a name, e.g. Compile & Execute. Then in the Command field enter the command line you would use in a terminal to compile and execute your files, substituting file and class names with variables (see the Geany manual).

For example, on Linux one would use javac "%f" && java "%e". (Using && ensures the resulting class file is only executed when compilation is succesful.)

Click OK and open the Build menu again to see the Compile & Execute command is now there. In my case Geany automatically assigned it the shortcut key F9. If there's no shortcut key you can assign one in Preferences > Keybindings.

Pressing your shortcut key will now run the command line you entered and display its output in the Compiler tab of the Message Window. Alternatively you can create your build command under Execute commands instead of Java commands, and it will be run in a terminal window instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top