I'm trying to run a simple program:
public class Greet {
public static void main(String[] args) {
System.out.println("HELLO");
}
}
But I get /bin/bash: line 2: $'\r': command not found
python: can't open file '/projects/GreetTest/main.py': [Errno 2] No such file or directory
as an output.
What can be done to make such simple console programs to be compiled and executed? I tried googling but had trouble finding a thorough tutorial.
EDIT: When I press run a newCustom
is run:
# execute a JAR
java -jar ${current.project.path}/target/application.jar
# execute python script
python ${current.project.path}/main.py
I tried deleting the python part so it's now:
# execute a JAR
java -jar ${current.project.path}/target/application.jar
and it gives an error:
Error: Unable to access jarfile /projects/GreetTest/target/application.jar
My file is titled Greet.java
.
Greet.java
. That file should contain exactly the code that you posted in your question, nothing more.javac Greet.java
.java Greet
.This assumes that you have a working JDK installed on your machine.
As stated in the comments before, it seems that you are trying to run your Java code with a Python interpreter. Python is a completely different programming environment.
Update: So, I had a look at Codenvy. They provide a complete Hello World example. Create a new workspace, select the "Java" quick start stack and add the
console-java-simple
project to the workspace. Then run theconsole-java-simple: run
Maven task. You can get a list of the project's Maven tasks by pressingShift+F10
.The
HelloWorld.java
file in their example is almost identical to yourGreet.java
.Here's how to do it step by step:
Create Workspace
(underRecent Workspaces
)Java - Default Java Stack with JDK 8, Maven and Tomcat.
(not the preselected one that includes MySQL).Add or Import Project
and check theconsole-java-simple
project. Then clickAdd
.Create
button at the bottom, or the one in the upper right corner. The workspace gets created and the view switches to the new workspace. Wait until you see a notification in the upper right corner telling you that theconsole-java-simple
project was successfully imported.Shift+F10
.run
Maven task.In the project explorer, under
console-java-simple/src/main/java/org.eclipse.che.examples/
, you can find theHelloWorld.java
.Update: By the way, I don't think that Codenvy is the right tool to get started with Java. It's not meant to be a quick and easy way to play around with Java but instead a full blown IDE running in the browser. You have to deal with a lot of distractions from actual Java programming, like build tools (e.g. Maven) to get anything running.
If getting started with Java is what you are aiming at, I'd recommend to find a way to get a JDK installed locally and then play around with that.