Ubuntu 16.04 desktop / Oracle Java 8
Task: you need to create a script that first compiles the source, for example file.java into file.class for later launch directly by the java program. All this mess happens in gnome-terminal . The .java and .class files may be in the same directory as the script, although I would certainly like to scatter them into the source and classes folders. The script is launched from the GUI. For example, here is what .bat file I had in Windows:
cd source javac -d ../classes Solution.java cd ../classes java Solution pause We take Solution.java from the source folder, compile, and put the result in classes . Then we run the compiled file. If as a result of compilation errors occur, the Windows console displays these errors in the console, but then still runs Solution.class , if it exists in the directory, of course. The main thing is that all this happened sequentially - first compilation, then launch. All this is necessary in order not to write the full path to the files for compilation and launch to the console each time (besides, the path is long). Having spent several keyboards on the head, the working version came out like this:
1) create a file, for example run.sh
2) In Sv-Vah we put a daw that it is executable
3) in the settings of the nautilus set "run executable files"
4) open a text editor file, and write in it:
#!/bin/bash gnome-terminal -x bash -c 'javac Hello.java && java Hello && read L' As a result, we get an almost perfect picture. Everything will happen sequentially: The compiler (javac) is started , it performs its shamanic business with Hello.java , and if everything is fine , it spits out Hello.class to the same directory, where then the java program launches Hello.class for execution. However, if there is an error in the code, the compiler will not work and the console will simply close without even reporting the type of error that occurred. That's the problem.
DECISION
#!/bin/bash gnome-terminal -x bash -c 'cd source && javac -d ../classes Hello.java && cd .. && cd classes && java Hello;read' The script should be in the root, along with the source and classes folders. The source folder should be the source (in my case, Hello.java). The compiled version (Hello.class) is put in classes and starts.
alexander barakin, DimXenon - thank you