3

Before you read, understand I'm clearly a noob (Actually, I don't even know anything about programming yet). I wanted to start learning-practicing with Java using an online IDE. In this case, I'm using Codenvy (www.codenvy.com). It's clearly beautiful and awesome, but I have a question. In Eclipse or DrJava or whatever (simple IDEs), to make "Hello World", you need to do this...

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

As said on websites like this: http://goo.gl/vYhP83

On Codenvy, it looks to be "harder" (obviously, it's easy when you know, but harder in the meaning that there're more things to do). On samples of Hello World, I see folders, packages, .xml and external libraries. Can somebody tell me how to do (step by step if possible, without ignoring anything, I'm a noob after all) "Hello World" on Codenvy? And explain me why it's different from Eclipse, for example. Please, don't say "Go to Eclipse, you're drunk". I want to understand Codenvy, I think I will learn from understanding Codenvy. Thanks you.

durron597
  • 31,968
  • 17
  • 99
  • 158
Fallen Being
  • 49
  • 1
  • 3
  • It's not actually different from doing it in Eclipse. Codenvy probably has all those xml files and external libraries because the example is meant to be compiled for an Android device, whereas in Eclipse, you get output on the console. It's the difference between writing a Hello world Program and a Hello World App – Aify Sep 14 '15 at 21:40
  • I promise you I'm sorry if you feel stupid for helping me, but I really want to learn. http://i.imgur.com/jxWf8Jd.png Why it doesn't work? In Eclipse, it does! – Fallen Being Sep 14 '15 at 21:44
  • Uh... I have no idea why it doesn't work, because that picture looks fine to me. You said it yourself, the code runs fine in Eclipse, so there's nothing wrong with the code. It's probably some Codenvy thing that you didn't set up properly (I haven't used Codenvy before so I can't tell you for sure). – Aify Sep 14 '15 at 21:47
  • 1
    Sorry if my question is stupid or bad explained, first time using StackOverFlow :) I'll improve as much as I can! – Fallen Being Sep 14 '15 at 21:48
  • In Java, public classes must have the same name as the file they're in. Try renaming either the class or the file. – Cinnam Sep 14 '15 at 21:49
  • Don't worry Aify, thanks. I'll discover by myself even if nobody helps me :) (Sorry if this is considered spamming via comments) – Fallen Being Sep 14 '15 at 21:49
  • There you have, Cinnam. http://i.imgur.com/2yrmdej.png Nothing. (Thanks for the answer) – Fallen Being Sep 14 '15 at 21:53
  • I'm not familiar with Codenvy, but there should be a Clean&Build option somewhere in the menu. Use it and look for any error messages in the console, it should tell you what's wrong (apart from the message that it can't access the jar). – Cinnam Sep 14 '15 at 21:57

3 Answers3

2

Codenvy uses Maven and Ant as default build managers. Your app has to be packaged as JAR and this JAR is then executed. Thus, you need to have pom.xml or build.xml file in your project.

The best way for you to get started is to create a sample app from the project wizard - Maven Console.

enter image description here

It's a bit different from Eclipse where all you need is your class and Java installed.

bianchi
  • 500
  • 2
  • 12
1

This is tutorial for simple Java "Hello World":

http://www.smlcodes.com/tutorials/codenvy-java-onepage-tutorial

At step 4 I had to make googling this tutorial.

enter image description here

Community
  • 1
  • 1
Grigory Kislin
  • 16,647
  • 10
  • 125
  • 197
0

So, in order to run any compiled languages (such as Java), your code needs to be compiled. You can compile/build your project with Maven/Ant, but indeed this can be a bit cumbersome if you quickly want to script and test something. Many IDE's can quickly compile and run a single class for you when you press run.

Although it seems codenvy does not come with this functionality by default, we can easily script compiling and running a file. Go to commands and add a new one (by pressing '+'). Within the command line field enter:

javac ${explorer.current.file.path}; 
SP=${project.java.sourcepath}; 
cd ../${current.project.path}/${SP//:/ }[0];
java ${current.class.fqn};

Here we basically ask java to compile the selected file and to run it afterwards (probably someone can come up with a more sophisticated way to do this, but at least it should give you some basic functionality).

Note: If you depend on multiple java files, you will have to compile those too, at this point it may become easier to go trough an online tutorial on how to use Ant.