How to run java programs in Atom editor


#1

Hello

I want to run Java programs in the Atom editor. However, with heavy research I have come to no solution. The first error I can not seem to overcome is “Selection Based runner not available for Java”. I am still new to programming so I would greatly appreciate any feedback. The more detail the better. Thanks!

I am using Windows 10.
Packages installed include- atom runner, script, set-syntax


#2

Break it down a bit more. I know script has an option to run by selection, so that’s the one you’re using? It sounds like you need to run the whole script at once.


#3

Bare with me
I go to Packages - Script - Run Script (or Ctrl+Shft+B) and get this

I have already selected Java as the language.

How do I configure this

into the script or am I suppost to add the Java language to the atom-runner?


#4

That’s nothing to do with either of the packages. If you go to your System settings and click on Advanced System Settings, it brings up a window with a button that says Environment Variables at the bottom. You can click on that and then there are two Path variables, one for the user in the top window and one for the whole system in the bottom. Look in both of them for something that looks like it points to the JDK on your computer. If that’s not present, that might be the cause your error.

or am I suppost to add the Java language to the atom-runner?

Is that what the Runner documentation says to do? I think you’re getting ahead of yourself, trying to get two different packages to work at the same time, and you aren’t differentiating between them in your questions. Focus on Script for now.


#5

Java isn’t designed to be executed in a selection-based or line-by-line way like scripting languages are. I’m not surprised that there is no support for executing Java in this manner. I doubt there is a way around this error.


#6

As for the Environment Variables this is what it looks like

If it is too much trouble to run Java in the Atom editor I can always just use Netbeans. I just don’t understand what I am doing wrong where it goes to the point where I can not use an entire language in Atom. Has anyone else found success in being able to run Java programs in Atom?

I also tried to run ruby and I receive this error “‘ruby’ is not recognized as an internal or external command,
operable program or batch file.”

My environment variables for Ruby look like this


#7

You can’t use any language in Atom except for HTML, CSS, Less, or JavaScript/CoffeeScript. Packages like Script and Runner mediate with external tools. If the Script documentation is not sufficient to successfully execute Java, then you should bring up the issue with the package authors.

As for the Environment Variables this is what it looks like
https://gyazo.com/fe9396e0a9a39f7984660502e5fb7d82

You have not yet demonstrated that you have followed the instructions in the Script docs. You need to actually open up the Path environment variable so that we can see the individual directories it points to. If there’s not a ...\jdk1.x.x_xx\bin\ somewhere in there, then you need to add it (with the version number of your instance of JDK, of course).

I also tried to run ruby and I receive this error “‘ruby’ is not recognized as an internal or external command, operable program or batch file.”

Because the Ruby executable is not in your Path. What’s in the C:\Ruby23-x64 directory?


#8

Java isn’t a scripting language like Ruby, Python or Perl. Java is intended to be a compiled language where you build an entire program and execute it as a comprehensive whole. Atom supports Java as much as it supports any other language, it allows you to edit the code. Executing the code is outside the scope of what Atom provides. For more information, see the Atom FAQ:

If you need support for Java, what it is intended for and how to make it work, Oracle’s documentation or Stack Overflow would probably be better resources.


#9

I fixed my Ruby issue.

After installing the latest version of Ruby

I installed Rapid Environment Editor to edit the paths for me.
http://www.rapidee.com/en/download

After installing the editor I had to restart it as administrator.

Next, right click your path

Add value > Insert Directory Path > select the Ruby bin

Open your command prompt and type ruby.
If the same error that you received in atom does not occur in the command prompt than cheers!


#10

As for the Java path.


#11

In that case, you’ve satisfied what the docs ask you to do and you should bring that up as an issue with the maintainers of the package.


#12

I’ve succesfully built .java files by using the Package - Script on Mac OS X and doing a Command-i to build the java file and execute. This brings up a command execution in the lower pane and shows the output of the run.


#13

You need to have a full class code if you want to run Java. Java cannot be ran if it’s not embedded in a class structure. Interpreted languages like python can be, but not Java. so a hello world in Java looks like this:

class HelloWorld {
     public static void main(String[] args){
        System.out.println("Hello World");
    }
}

Keep in mind that the filename must be the same as the class name. In this case : HelloWorld.java


#14

Java can be hacked to be executed line by line: http://www.javarepl.com/console.html

However, it’s not pleasant, and I wouldn’t recommend it. If you really like java and also really want an interpreted language, Scala is pretty close, and comes with a repl by default.

All that said, atom is an editor. Java, by design, nearly requires the use of an IDE to code effectively. It has very strict formatting requirements, a lot of ways to do the same thing, and a tendency toward longer variable/class names, lines of code, and files (verbosity).

I use atom at work to write ruby and python, and intellij for java. If you really want to run java programs in atom, why not try one of the terminal programs? https://atom.io/packages/terminal-plus works pretty well, and you can javac and java there just like you could regularly on the command line.