Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 943
cjones Avatar asked Jan 28 '15 15:01

cjones


3 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.

like image 176
Brady Dowling Avatar answered Oct 06 '22 15:10

Brady Dowling


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).

like image 23
gaal Avatar answered Oct 06 '22 15:10

gaal


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).

BuilderRunner

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

like image 21
cjones Avatar answered Oct 06 '22 17:10

cjones