Cant run java program on raspberry Pi [duplicate] - java

This question already has an answer here:
JavaFx Ensemble on Raspberry pi
(1 answer)
Closed 7 years ago.
I have downloaded the latest OS for the pi from here http://downloads.raspberrypi.org/raspbian_latest
Then i have downloaded the latest Java JDK to run my JavaFX application from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and selected the Hard Flat v6/v7 file.
I have transferred and unzipped the JavaJDK onto my Pi.
Now if i execute this command on my local machine, my application starts
Java -jar program_name.jar
But if i run the same command on the Pi, i get an error saying
Could not find or load main class application.Main
If i change the .jar file into a .zip, i can clearly see a directory called application, and file called Main.class
So why is my program working on my (windows 10) machine, whether i run it from eclipse or the command line, but not on the raspberry Pi?

To install the Java Runtime Environment (JRE) run the following command:
sudo apt-get install openjdk-7-jre
This installs the Java JRE (Java Runtime Environment) which will allow you to run applications written in Java.
To install the JDK run the command:
sudo apt-get install openjdk-7-jdk
This allows you to compile Java applications to bytecode.
If you want the Oracle Java VM, which is a lot faster (optimized for embedded arm CPUs) and is also a developer preview (applications maybe buggy or crash) until some time into the future. Instead of the above instructions you need to download the file called Oracle JDK 8 (with JavaFX) for ARM Early Access on the Oracle Java 8 download page.
Remember to download the Oracle Java system on your Pi, or you won't be able to install it.
To install the Oracle Java System:
sudo tar zxvf jdk-8-ea-b36e-linux-arm-hflt-*.tar.gz -C /opt
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk1.8.0/bin/java" 1
sudo update-alternatives for other commands if needed (e.g. javac).
java -version
Then it is all installed.
Another thing, if you have more then one Java runtime installed you have to check which version you use with the command java -version. If the output is:
java version 1.5.0 gij (GNU libgij)
Then you are using another java runtime. You can resolve the issue by running
sudo update-alternatives --config java
and choosing the OpenJDK or Oracle option.

Related

JavaFX on Oracle Linux 8.6

I have a Java application which uses javaFX to process images (using the javafx.scene.image.Image and some related functionality, and instantiating an javafx/embed/swing/JFXPanel object to force JavaFX to initialise). I'm trying to run this application on an Oracle free server running Oracle Linux 8.6 with Oracle Java 1.8.0_351 (OpenJDK and Oracle Java 19 give errors relating to JavaFX not being present). I've compiled my application into a JAR (compiling for Java 1.8.0_301 using Oracle Java on Windows). However, on the server, this doesn't work; I get the exception java.lang.UnsupportedOperationException: Unable to open DISPLAY.
This question's answer suggests using xvfb:
Deploy JavaFX on Ubuntu server without display
I've tried this, but get a "GLX version 1.3 or higher is required" error instead.
Is there a solution for running JavaFX with Oracle Linux?
What I've tried:
I've tried with two different OSes available with Oracle free;
Oracle Linux 8.6
OpenJDK was installed with sudo dnf install java-1.8.0-openjdk-devel.x86_64.
Running the jar gives the NoClassDefFoundError error.
I couldn't work out how to install javafx with dnf on Oracle Linux.
I decided to give Oracle Java a go; OpenJDK was unlinked with sudo unlink /etc/alternatives/java.
The Oracle jdk 19 was downloaded and installed with sudo rpm -ivh jdk-19_linux-x64_bin.rpm. Running the jar (with java -jar MyJar.jar) still gives the same error.
I tried uninstalling that (with sudo dnf remove jdk-19) and openJDK (with sudo dnf remove java) and installing Oracle Java 1.8.0 from a .rpm file. I then get an java.lang.UnsupportedOperationException: Unable to open DISPLAY error.
Xvfb was installed using sudo dnf install xorg-x11-server-Xvfb. xdpyinfo was installed using sudo dnf install xdpyinfo.
Xvfb was started using export DISPLAY=:99 and sudo xdpyinfo -display $DISPLAY > /dev/null || Xvfb $DISPLAY -screen 0 1024x768x16 & (taken from here: https://unix.stackexchange.com/a/297882 )
When running the JAR, I then get the exception
ES2 Prism: Error - GLX extension is not supported
GLX version 1.3 or higher is required
java.lang.UnsupportedOperationException: Internal Error
Canonical Ubuntu 22.04 Minimal
OpenJDK was installed with sudo apt-get install openjdk-8-jdk.
Running the jar gives the NoClassDefFoundError error.
OpenJFX was installed with sudo apt-get install openjfx. Same error.
I tried running the JAR with --module-path argument pointing to /usr/share/openjfx/lib/; --module-path is an unrecognised option with Java 8.
I upgraded to the latest openjdk sudo apt-get install openjdk. After this I'm able to use --module-path.
I tried running the JAR with java --module-path /usr/share/openjfx/lib/ --add-modules javafx.controls,javafx.base,javafx.graphics,javafx.swing -jar MyJar.jar (I'm not sure which modules correspond to which packages...). This causes a java.lang.UnsupportedOperationException: Unable to open DISPLAY error.

How to uninstall Java 9 on macOS Sierra

I'm having trouble removing Java 9 from my macOS Sierra system.
I accidentally installed Java 9, instead of Java 8, so now all my Eclipse projects give me these warnings: Build path specifies execution environment JavaSE-1.8. There are no JREs installed in the workspace that are strictly compatible with this environment.
I have used the following guide, but it did not work. Here is my command output when running java -version from the command line:
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
for macOS high sierra removing java 9:
delete the java folder you find in the dir shown to you after executing:
/usr/libexec/java_home -V
use "Go to" in finder and copy and paste the dir to get there
There are two commands which are very simple and useful. If you want to keep multiple versions simply set JAVA_HOME to version you want to use.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_(version you want to use).jdk/Contents/Home
Example--> export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
Else in addition to above command remove/uninstall additional jdk version from your system with below command.
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-(version you want to remove).jdk/
Example --> sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/
Please refer below github link for additional details -->
https://gist.github.com/schnell18/bcb9833f725be22f6acd01f94b486392
Thanks
On MacOS you can list what JDKs you have installed and where they are installed to with:
/usr/libexec/java_home -V
If you want to select one of the installed JDKs to be used as default, you can do:
/usr/libexec/java_home -v 1.8
Verify which is now default with java -version.
You can manually add the location of other installed JREs in Eclipse via Preferences / Java / Installed JREs , press Add, and then point it to one of the locations should with the -V option above. You can then check it to select which is default for your projects.
After viewing which Java Virtual Machines I had on my computer using the following command:
ls /Library/Java/JavaVirtualMachines
I realized no additional JDK's would appear after using the Java 8 installer (besides Java 9). When doing further research, it turns out I had installed the other version that is not a SE development kit and it was just working in web browsers, not for the terminal.
For anyone having the same issue, make sure you use the Java SE Development Kit 8.
Uninstall Oracle Java using the Terminal:
Note: To uninstall Java, you must have Administrator privileges and execute the remove command either as root or by using the sudo tool.
Remove one directory and one file (a symlink), as follows:
Click on the Finder icon located in your dock
Click on the Utilities folder
Double-click on the Terminal icon
In the Terminal window Copy and Paste the commands below:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Java
Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.
Source:https://www.java.com/en/
I believe the problem is navigating to the correct directory... Once you are where you are supposed to be you can run the sudo commands to remove whichever versions of java you want to remove.
First, run the command in the terminal to determine which version of Java you are running,
java -version
then you can navigate to pesky version of java that you intend to delete by using the following command:
cd /Library/Java/JavaVirtualMachines
then once you see are in the JavaVirtualMachines path, type in ls to see what versions of Java you have installed,
ls
and finally when you know which version or versions of Java you want to uninstall:
sudo rm -rf jdk-10.0.1.jdk #or whichever version you want to delete
I know that you've asked about how to uninstall the java version. But, I think it's important how to manage your Java version in a very good way.
For me, the best way is using SDKMan, a very nice tool for managing you Development tools like Java.
Here you can learn more about it: http://sdkman.io/
You can install your Java version as follow:
$ sdk install java
You can install others tools like Scala:
$ sdk install scala 2.12.1
Uninstall your tools very easy:
$ sdk uninstall java 9
And so on. Hope this helps you in future installation of your development tools.

Java 8 application on EC2

I was wondering if anyone knows if it will be possible for me to install Java 8 on an EC2 instance. My application is packed as a fat jar with embedded jetty, so the Java 8 runtime alone should be sufficient.
I'm not too familiar with Linux, and I saw that they only had Java 7 support on the default AMI. Is there a simple command I can run to update to Java 8?
check Java current version
java -version
install Java 1.8
sudo yum install java-1.8.0
change the Java version
sudo alternatives --config java
Java 8 may not be available out-of-the-box on the AMI that you are looking for. However, you can always install it once the instance is created.
e.g. Check this post which explains how to install java 8 on Ubuntu OR check this post which explains how to install Java 8 on RHEL/Fedora/CentOS.
Installing JDK 8:
Step 1: Check the Java Version
java -version
Step 2: Download RPM package of Oracle JDK (8u121)
wget --no-check-certificate --no-cookies --header "Cookie:oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm
Step 4: Install JDK 8
sudo yum install -y jdk-8u141-linux-x64.rpm
Step 5: Verify oracle JDK version
java -version
Installing JRE 1.8
sudo yum install java-1.8.0
change the Java version
sudo alternatives --config java
Donwload Linux version of JRE from below link to your windows machine as it has browser. Note that if you are using this EC2 instance as server you just need JRE and not complete JDK.
https://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html
Tranfer downloaded .tar.gz file using winscp to your EC2 instance.
Run "tar zxvf jre-8uversion-linux-i586.tar.gz" on your EC2 instance. For more info https://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jre.html#CFHBHAGI
This question is old but this may help with Java 11. If anybody is interested in installing Java JDK 11, I run
sudo amazon-linux-extras install java-openjdk11
in my EC2 instance with Amazon Linux.
I got it from here:
https://tecadmin.net/install-java-on-amazon-linux/
You can install Amazon Corretto 8 as either the runtime environment (JRE) or the full development environment (JDK). The development environment includes the runtime environment.
sudo yum install java-11-amazon-corretto -y
You can follow the AWS official document from here: https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/amazon-linux-install.html

Eclipse can't find Java, Java not installed

I was following an online tutorial on how to delete JVM 6 and install JVM 7 to be able to run eclipse on my Mac running OS X 10.9.2. First I installed the latest JDK.
I was instructed to type the following commands to delete JVM 6.
sudo rm -rf /System/Library/Java/JavaVirtualMachines/
sudo rm /private/var/db/receipts/com.apple.pkg.JavaForMacOSX*
sudo emacs /Library/Receipts/InstallHistory.plist
Then, I set the symlinks for java 7, with these commands.
sudo rm /usr/bin/java
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/bin/java /usr/bin/java
This should be it. Now my computer does not have any version of Java on it:
the command "java -version" responds with "java: command not found"
I also cannot direct to the folder with cd Library/Java responding with "Folder does not exist", however I can browse to that folder manually.
Can someone please assist me in getting Java 7 running on my computer so I can use eclipse.
Any help much appreciated and keep in mind I'm a Mac newb.
this is the tutorial i followed:
http://www.cc.gatech.edu/~simpkins/teaching/gatech/cs2340/guides/java7-macosx.html
Did you change the PATH variable to point to the newer version?
/usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac.
I think that the folder still exists but executables didn't existe because anh version of Java is installed.
Normally you have just to download the jdk or jre on oracle web site and run the package downloaded

How to run simple java app on amazon ec2?

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
You need to install java-1.6.0-openjdk-devel:
yum install java-devel
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.
There's a few steps to do:
Make sure you have a Java compiler installed. You can find this out by entering $javac into your console and seeing what comes up. If it's not installed, follow the previously mentioned instructions to $yum install java-devel
Create your script (first.java)
Compile it using $javac first.java
You will now have first.java and first.class... execute it by executing $java first
"[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.
In order to create and run a basic java program on Amazon EC2, you would require to do following:
When you login to EC2 instance, check whether JDKis installed or not, fire javac -version for it.
If you do not have JDK installed you would see something like this:
Install JDK, fire sudo rpm -i jdk-8u11-linux-x64.rpm
Having java installed, you can create a file file.java using any editor.
Edit the file and save.
Compile java File, javac file.java
Run it, java file

Categories

Resources