Reputation: 4556
I have access to amazon cloud service ec2, linux instance. I created vi first.java
file with this content:
class first {
public static void main(String[] args) {
System.out.println("abc");
}
}
I want to compile the file using:
[root@ip-21-24-273-243 ec2-user]# javac first.java
bash: javac: command not found
Command not found? I do:
[root@ip-21-24-273-243 ec2-user]# java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.9) (amazon-57.1.11.9.52.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
So java is installed. How can I run a simple app?
[root@ip-21-24-273-243 ec2-user]# yum install java
Loaded plugins: priorities, security, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00
amzn-updates | 2.3 kB 00:00
Setting up Install Process
Package 1:java-1.6.0-openjdk-1.6.0.0-57.1.11.9.52.amzn1.x86_64 already installed and latest version
Nothing to do
Upvotes: 11
Views: 24599
Reputation: 5868
In order to create and run a basic java program on Amazon EC2
, you would require to do following:
EC2
instance, check whether JDK
is installed or not, fire javac -version for it.
If you do not have JDK
installed you would see something like this:
sudo rpm -i jdk-8u11-linux-x64.rpm
file.java
using any editor.javac file.java
java file
Upvotes: 0
Reputation: 105
There's a few steps to do:
$javac
into your console and seeing what comes up. If it's not installed, follow the previously mentioned instructions to $yum install java-devel
first.java
)$javac first.java
first.java
and first.class
... execute it by executing $java first
Upvotes: 1
Reputation: 22451
You need to install java-1.6.0-openjdk-devel:
yum install java-devel
Upvotes: 16
Reputation: 26204
As already mentioned, to compile a Java program you need JDK. Here you may find some useful information on how to install JDK on a Fedora AMI: Compiling and running Java app
However, you should notice that you don't need to compile on your ec2 instance. You can compile your Java program on your home desktop/laptop computer and transfer compiled .class (packed in a .jar) files to the instance, and run them there - the already installed JRE should be enough to run the program. That is a preferable approach, cause you can comfortably use Eclipse for development. Develop, test on your local machine, deploy on ec2.
Upvotes: 2
Reputation: 29385
"[Java] Runtime Environment" or "JRE" for short doesn't include the developer tools, one of them being the Java Compiler. You need to install Java Development Kit or "JDK" for short. The exact mechanism depends on which AMI you used to build your instance.
Upvotes: 0