Setting up Cloud9 IDE to compile and run Java?

16,698

Solution 1

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.

Solution 2

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

Solution 3

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

Builder Runner

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

Solution 4

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.

Solution 5

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

Example:

sudo apt-get install openjdk-7-jdk

Share:
16,698

Related videos on Youtube

cjones
Author by

cjones

Updated on September 23, 2022

Comments

  • cjones
    cjones over 1 year

    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.

  • cjones
    cjones about 9 years
    Yea, I wish I had seen that before. I just figured it out and then saw your post. Pretty much detailed exactly what I needed to do.