Setting up Cloud9 IDE to compile and run Java?

I have tried posting this request in Cloud9's forums, but since it never posts, I am hoping someone here could give me a hand. (The forum keeps saying my question is being submitted for review, but then never shows up).

I can't get Java code to compile and run. I've Googled the issue and read other posts in their limited forums, but I can't get it to compile and run a simple Hello World! program. My .java filename matches the class and the code is fine.

I have tried putting my .java files in the following directories:

test/java/

test/src/

I just get this:

bash: src/HelloWorld.java: No such file or directory

I tried this: http://www.programmingforliving.com/2014/09/java-coding-with-cloud9-ide.html

But I just get:

Running HelloWorld.java                                                                                                                                          

Error: Could not find or load main class HelloWorld  

Any suggestions? Given I'm essentially a Java noob I am hoping the solution is fairly simple.

Answers


Without you pasting in your code it's tough to tell but make sure your class and filename are both titled HelloWorld. Make sure your src folder is in your main workspace folder so your file should be at /home/ubuntu/workspace/src/HelloWorld.java.

Also, this documentation looks pretty similar to the blog you referenced but still worth a look https://docs.c9.io/docs/custom-runners.


I think that Codenvy is much better in java than Cloud9. It provides easy build & run configuration, code completion, project sharing with permissions or factory (creates clone of your project with one click in minutes). Take a look at official java spring factory. This link opens temporary(personal) java project ready to code, build & run. Also Codenvy has project wizard that has a lot of project types including java console app (uses maven).


Ok, decided to screw around with it and figured it out... (then saw that Brady Dowling had posted a link that explained in better detail what needed to be changed).

At any rate, I noticed a few things in Cloud9.

  1. Even after making the changes and saving, it would still not compile correctly. I had to close my session of C9 and go back in. Then it would work.
  2. After compiling, and trying to run the program, it wasn't automatically picking the Java runner I made. So if you are running into issues, make sure the Java (or whatever you decided to name it) runner is selected in the console.
  3. You have to compile and run separately. Kind of annoying, but at least it works. Unlike C/C++ in C9, it won't compile and run by simply hitting 'Run'. If you do, it creates an error saying the .class doesn't exist. Simple as pressing F7 to build, then F5 to run.

Anyway, I took screenshots of what I had to change to get it working. Essentially, just the directories it looks for the .java file in (the right arrows) and the directory it looks for/compiles the .class file to (the left arrows). Since I was putting the .java and .class in the same directory (java), I just changed both to 'java'. In the links Brady and myself posted, they used .bin (for .class) and src for (.java).

1st picture is the Builder file (I called it javac) and the 2nd picture is the Runner file (I called it Java).

Anyway, I hope this helps someone out. I am really liking C9 and it perfectly suits my novice needs at the moment. I like the ability to dabble in multiple languages to see what I like without having to switch applications. The real-time live preview HTML/CSS like Brackets is another huge plus for me.

Regards


For what I understand, C9 workspaces don't come with jdk installed. But I always use these commands:

  1. sudo apt-get update

(wait a while for it to finish processing. Then)

  1. sudo apt-get install default-jdk

(Then It will ask you for some permission. Type "Y")

And then it compiles and runs normally using the terminal.


Sometimes you will also need to install a package to get javac.

Example:

sudo apt-get install openjdk-7-jdk


The java command works right of the box. You may java -version to see that it is Ubuntu running. You can also locate the java binary and see that it is amd64. That is all you need to know to download jdk manually from Oracle.com, like

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-i586.tar.gz

tar xf jdk-8u92-linux-i586.tar.gz

and voila, jdk-1.8.0_92/bin/java(c) can be executed! It allows you to compile java files.


Need Your Help

best way to integrate wordpress forms with mailchimp

wordpress

How to integrate word press with mailchimp? is this possible to integrate with mailchimp?

Make function declarations based on function definitions

c++ function header declaration definition

I've written a .cpp file with a number of functions in it, and now need to declare them in the header file. It occurred to me that I could grep the file for the class name, and get the declaration...