设置 Cloud9 IDE 来编译和运行 Java?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28196434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:10:46  来源:igfitidea点击:

Setting up Cloud9 IDE to compile and run Java?

javacompiler-errorsidecloud9-ide

提问by eox.dev

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

我曾尝试在 Cloud9 的论坛上发布此请求,但由于它从未发布过,我希望这里有人可以帮助我。(论坛一直说我的问题正在提交审核,但从未出现)。

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.

我无法编译和运行 Java 代码。我在谷歌上搜索了这个问题并阅读了他们有限论坛中的其他帖子,但我无法编译和运行一个简单的 Hello World!程序。我的 .java 文件名与类匹配,代码很好。

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

我曾尝试将我的 .java 文件放在以下目录中:

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

我试过这个: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.

有什么建议?鉴于我本质上是一个 Java 菜鸟,我希望解决方案相当简单。

采纳答案by Brady Dowling

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 srcfolder is in your main workspace folder so your file should be at /home/ubuntu/workspace/src/HelloWorld.java.

如果不粘贴代码,很难判断,但请确保您的类和文件名都标题为 HelloWorld。确保您的src文件夹位于主工作区文件夹中,因此您的文件应位于/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.

此外,该文档看起来与您引用的博客非常相似,但仍然值得一看https://docs.c9.io/docs/custom-runners

回答by gaal

I think that Codenvyis 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).

我认为Codenvy在 Java 中比 Cloud9 好得多。它提供了简单的构建和运行配置、代码完成、具有权限或工厂的项目共享(一键在几分钟内创建项目的克隆)。看看官方的java spring factory。此链接打开临时(个人)Java 项目,准备编码、构建和运行。Codenvy 也有项目向导,它有很多项目类型,包括 java 控制台应用程序(使用 maven)。

回答by eox.dev

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

好吧,决定解决它并弄清楚......(然后看到 Brady Dowling 发布了一个链接,更详细地解释了需要更改的内容)。

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

无论如何,我在 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.
  1. 即使在进行更改并保存之后,它仍然无法正确编译。我不得不关闭我的 C9 会话并返回。然后它会起作用。
  2. 编译并尝试运行程序后,它并没有自动选择我制作的 Java 运行程序。因此,如果您遇到问题,请确保在控制台中选择了 Java(或您决定命名的任何内容)运行程序。
  3. 您必须单独编译和运行。有点烦人,但至少它有效。与 C9 中的 C/C++ 不同,它不会通过简单地点击“运行”来编译和运行。如果这样做,它会创建一个错误,指出 .class 不存在。简单的按 F7 构建,然后按 F5 运行。

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

无论如何,我截取了我必须更改才能使其正常工作的屏幕截图。本质上,只是它在(右箭头)中查找 .java 文件的目录和它查找/编译 .class 文件的目录(左箭头)。由于我将 .java 和 .class 放在同一个目录 (java) 中,我只是将两者都更改为“java”。在 Brady 和我发布的链接中,他们使用 .bin(用于 .class)和 src 用于(.java)。

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

第一张图是 Builder 文件(我叫它 javac),第二张图是 Runner 文件(我叫它 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.

无论如何,我希望这可以帮助某人。我真的很喜欢 C9,它现在非常适合我的新手需求。我喜欢能够涉足多种语言以查看我喜欢的内容而无需切换应用程序。像 Brackets 这样的实时实时预览 HTML/CSS 对我来说是另一个巨大的优势。

Regards

问候

回答by Vivian Magri

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

据我了解,C9 工作区没有安装 jdk。但我总是使用这些命令:

  1. sudo apt-get update
  1. sudo apt-get 更新

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

(等待它完成处理。然后)

  1. sudo apt-get install default-jdk
  1. sudo apt-get install default-jdk

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

(然后它会要求你获得一些许可。输入“Y”)

And then it compiles and runs normally using the terminal.

然后它使用终端编译并正常运行。

回答by szszptr

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

有时您还需要安装一个包来获取 javac。

Example:

例子:

sudo apt-get install openjdk-7-jdk

sudo apt-get install openjdk-7-jdk

回答by Little Alien

The javacommand works right of the box. You may java -versionto 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

java命令在框的右侧工作。您可能java -version会看到它正在运行 Ubuntu。您还可以找到 java 二进制文件并看到它是 amd64。这就是从 Oracle.com 手动下载 jdk 所需知道的全部内容,例如

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.

瞧,jdk-1.8.0_92/bin/java(c)可以执行了!它允许您编译java文件。