简体   繁体   English

在Codenvy上使用Java创建“Hello World”

[英]Create “Hello World” using Java on Codenvy

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. 我想开始学习 - 使用在线IDE练习Java。 In this case, I'm using Codenvy (www.codenvy.com). 在这种情况下,我正在使用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... 在Eclipse或DrJava或其他(简单的IDE)中,要制作“Hello World”,你需要这样做......

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

As said on websites like this: http://goo.gl/vYhP83 如上所述: 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). 在Codenvy,它看起来“更难”(显然,当你知道时它很容易,但更难以理解还有更多事情要做)。 On samples of Hello World, I see folders, packages, .xml and external libraries. 在Hello World的示例中,我看到了文件夹,包,.xml和外部库。 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? 有人可以告诉我该怎么做(如果可能的话,一步一步,不要忽视任何事情,毕竟我是个菜鸟)Codenvy上的“Hello World”? And explain me why it's different from Eclipse, for example. 并解释一下为什么它与Eclipse不同,例如。 Please, don't say "Go to Eclipse, you're drunk". 请不要说“去Eclipse,你喝醉了”。 I want to understand Codenvy, I think I will learn from understanding Codenvy. 我想了解Codenvy,我想我将从对Codenvy的理解中学习。 Thanks you. 谢谢。

Codenvy uses Maven and Ant as default build managers. Codenvy使用Maven和Ant作为默认构建管理器。 Your app has to be packaged as JAR and this JAR is then executed. 您的应用必须打包为JAR,然后执行此JAR。 Thus, you need to have pom.xml or build.xml file in your project. 因此,您需要在项目中包含pom.xml或build.xml文件。

The best way for you to get started is to create a sample app from the project wizard - Maven Console. 开始使用的最佳方法是从项目向导 - Maven Console创建一个示例应用程序。

在此输入图像描述

It's a bit different from Eclipse where all you need is your class and Java installed. 它与Eclipse有点不同,您需要的只是您的类和Java安装。

This is tutorial for simple Java "Hello World": 这是简单Java“Hello World”的教程:

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

At step 4 I had to make googling this tutorial. 在第4步,我不得不谷歌搜索本教程。

在此输入图像描述

So, in order to run any compiled languages (such as Java), your code needs to be compiled. 因此,为了运行任何编译语言(例如Java),需要编译代码。 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. 您可以使用Maven / Ant编译/构建项目,但如果您想快速编写脚本并测试某些内容,这确实有点麻烦。 Many IDE's can quickly compile and run a single class for you when you press run. 当您按下运行时,许多IDE可以快速编译并运行单个类。

Although it seems codenvy does not come with this functionality by default, we can easily script compiling and running a file. 虽然默认情况下codenvy似乎没有附带此功能,但我们可以轻松地编写脚本并运行文件。 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). 在这里,我们基本上要求java编译所选文件并在之后运行它(可能有人可以提出更复杂的方法来执行此操作,但至少它应该为您提供一些基本功能)。

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. 注意:如果你依赖于多个java文件,你也必须编译它们,此时通过关于如何使用Ant的在线教程可能会变得更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM