I've dabbled with Linux in the past, but my MB pro is dying -- started yesterday, in fact -- and it's time to switch. I have experience with the command line in the Terminal app, so most of the commands -- at least the basic ones -- I'm familiar with in Linux.
I 'm running elementary OS, and was able to download and install the Open JDK for Java 17. I'm working on a project as a way of learning Java. I have a folder labeled "Contacts Java Classes", and I know how to get to the folder, etc. There's a file that I want to run which contains the main method to get things going -- 'MainWIndow.java'
I can compile the file. Before when I tried to run the file w/o compiling I got this error:
Error: LinkageError occurred while loading main class MainWindow
java.lang.UnsupportedClassVersionError: MainWindow has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 61.0
After compiling the file, and trying to run it I get this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2393)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:285)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2398)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1392)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1390)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.desktop/java.awt.Toolkit.loadLibraries(Toolkit.java:1389)
at java.desktop/java.awt.Toolkit.initStatic(Toolkit.java:1427)
at java.desktop/java.awt.Toolkit.<clinit>(Toolkit.java:1401)
at java.desktop/java.awt.Component.<clinit>(Component.java:624)
at MainWindow.<init>(MainWindow.java:10)
at MainWindow.main(MainWindow.java:52)
Everything works fine on my MB Pro. But even thought I've dabbled before in Linux -- and I just mean dabble, since I always had my OS X -- I'm not sure what's going on.
Should I upgrade to Java 18? And if so, what's the best way to do it? Can anyone help me out? I'v been on other forums, but I'm not sure what I need to sak, and I think I may have gotten under some people's skin. The installing on OS X is easy, but it's more complicated here in Linux, and I'm not sure where to go.
I currently have the open JDK version, but there are versions on Oracle's site (Are they the same thing?). I tried downloading and installing them once last December, but I wasn't sure how to proceed, which versions I needed, and it was somewhat confusing trying to find the answers on the web.
Please offer me any assistance if you can. I wish to stress that my knowledge of Linux is very slight at this point, and I just want to get Java going on it, while I learn more about Linux. Does that make sense?
Related
PREFACE! I know similar questions have been asked a million times. I have read MANY hundreds of the previous questions and still cannot find my answer.
I am working on a raspberry pi and trying to run a Java application that is packaged in a Jar file. It was working fine before I installed the latest Java 1.8_111. I downgraded and it still didn't work. I then wiped my pi to defaults and it is still not working.
The current Java version is 1.8.0_65. I have decided that the java version is irrelevant by installing multiple different versions with the same result. When I installed a different version no other version was present to cause conflicts.
If I run the jar by simply doing java -jar KitchenScr.jar I get the following error:
Error: Could not find or load main class com.javafx.main.Main
If I run the jar from the supplied shell script(below). I get the following error.
Script
#!/bin/sh
DIRNAME=`dirname $0`
CP=$DIRNAME/KitchenScr.jar
# start uniCenta oPOS
java -cp $CP uk.chromis.kitchenscr.KitchenScr
Error
Error: Could not find or load main class uk.chromis.kitchenscr.KitchenScr
If I left anything out please let me know.
This was a simple issue that was staring me in the face.
Error: Could not find or load main class com.javafx.main.Main
Oracle stopped releasing JavaFX for ARM around Update 30 or something. It worked initially when I first bought my pi, but not after I installed a new OS because a newer version of Java was running.
Downgrade Java or add relevent ARM libraries for JavaFX.
mine worked. CP=$DIRNAME/KitchenScr.jar, I changed the capital letters of kitchenscr.jar to CP=$DIRNAME/kitchenscr.jar
Im running Java 1.8.0_065 (64 Bit) on Windows 10 (64 bit). I've downloaded the latest cmake version (3.4.0-rc2) for windows and the latest VTK sources (6.3.0). I generated a VS2015 solution via cmake and set up everything (seemingly!!) successfully using this tutorial:
https://www.particleincell.com/2011/vtk-java-visualization/
When I try to run the DemoJavaVTK.java which is provided by the tutorial I get linker errors in IntelliJ. (14.1.5) At apperently every VTK library that has to be loaded there is the same error:
java.lang.UnsatisfiedLinkError: C:\Program Files\VTK\bin\ANY_VTK_DLL.dll: Can't find dependent libraries at
java.lang.ClassLoader$NativeLibrary.load(Native Method) at
java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938) at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854) at
java.lang.Runtime.loadLibrary0(Runtime.java:870) at
java.lang.System.loadLibrary(System.java:1122) at
vtk.vtkNativeLibrary.LoadLibrary(vtkNativeLibrary.java:223) at
vtk.vtkNativeLibrary.LoadAllNativeLibraries(vtkNativeLibrary.java:158)
at sample.DemoJavaVTK.(DemoJavaVTK.java:54) at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:264) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
Mind that ANY_VTK_DLL is just a placeholder. Concrete examples would be: vtkViewsContext2DJava.dll or vtkRenderingVolumeOpenGLJava.dll.
The path should be correct. All the "versions" are 64 bit. I compiled VTK for 64 Bit. I'm running a 64 bit OS with 64 bit java.
The wierdest thing is: Using eclipse everything works fine and I can run the VTK-demo without any problems. Also I'm using VTK for a course at my university, I'm working on my project with a colleague who has the same java and intellij version. He also used the same tutorial to set up VTK/Java. And the example also works in IntelliJ for him. The only difference I can tell between his and my system is, that he is using Windows 8.1 and I am using windows 10.
I really don't know where to continue from here. What is IntelliJs problem?
Got it fixed out of pure randomness by manually setting the JRE via the Run-configurations:
http://puu.sh/l3315/7c1d5e3393.png
Why does this work?
Update:
The UnsatisfiedLinkError denotes that the Java Virtual Machine (JVM) cannot find an appropriate native-language definition of a method declared as native. Specifically, in order to find the required native library, the JVM looks in both the PATH environment variable and the java.library.path system property. (Got from this article)
I used to have this kind of problems mostly because two causes:
The native librarie cannot be found (i.e don't exist)
The library being linked is not the same (Debug vs Release, 32 bit
vs 64 bit, VC10 vs VC9, etc.)
The library is already loaded by your application and the application tries to load it again
The native library is present either in the java.library.path or in the PATH environment library of your application
In order to be sure to whom library you are linking use Dependency Walker. Using this tool will make you understand what's wrong by telling you to which native libraries you are linking to.
Download the tool and then open C:\Program Files\VTK\bin\ANY_VTK_DLL.dll to see to which library it's linking to and where they are in your machine. Then make sure that IntelliJ can find these paths.
Here is a good tuto on how to use this tool: http://www-archive.mozilla.org/quality/help/dependency-walker.html
If they are the correct ones, verify the class path that IntelliJ Idea uses to launch your application to check that the native libraries are there.
I could run using,
System.setProperty("vtk.lib.dir", YourBuildVTKLibPath);
I am new using VTK, took me a while to fix this, I am using eclipse ,
I added to the PATH environment variable the dll folder and the lib folder
First off, I've been trying to launch Eclipse but I kept getting the below error
Failed to load JNI shared library "C:\Program Files (x86)\Java\jdk1.8.0_25\bin...\jre\bin\client\jvm.dll"
So I looked through this thread
Failed to load the JNI shared Library (JDK)
The sensing I got was that I might want to uninstall Java and make sure I have the right 64 bit version, since I already have a 64 bit Eclipse.
I went ahead and went to uninstall the Java Update files via the control panel, which went fine.
Then when I tried to delete the Java files in my Program Files (x86) folder, I can't do it as the "file is being used by another process"
Now I can't install a new version of Java as I get an error code 1603 owing to the incomplete Java files, and I still got my JNI shared library error to fix.
I'm really stuck now. What do I do?
If you use 64 bit eclipse, you need a 64 bit operating system and 64 bit JDK. Close your eclipse and JDK, remove X86 JDK and install 64bit JDK.
ctrl+shift+esc open task manager and end all processes that are opened by java. Sometimes when you run java and your applications don't close properly, java run-time environment is still running. So you have to force java out of that state. Next time, i'd just install the newer version of java right on top of the old one. Because the installation process removes the old version of java for you and replaces it with the newest one.
with jframes using the code
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
this is essential to your program so it closes completely.
Sorry I couldn't be more specific with the question itself. Here's what I'm running: Windows 7 64bit, JDK v7, JRE v7 (64 bit), and JRE v6 (32 bit). I'm pretty new when it comes to Java, however I do know how to compile a program and all that stuff. I kept getting an error when I tried running my compiled programs:
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>javac ch3p1.java
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java ch3p1
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.c
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java -cp ch3p1
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.c
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java cd3p1
Exception in thread "main" java.lang.NoClassDefFoundError: cd3p1
Caused by: java.lang.ClassNotFoundException: cd3p1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: cd3p1. Program will exit.
C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1>java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
note that it couldn't find the file because I had changed the folder name to see if it would automatically detect the 64 bit JRE I have installed
However, after enough searching I found a page that stated my problems were because I was running a program I compiled on JDK v7 in JREv6. I messed around with that for a little while, trying to get it to run in the JRE that came with my download of JDK.
CD: C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1
Current directory: C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1
javac ch3p1.java
Process started >>>
<<< Process finished.
C:\Program Files\Java\jre7\bin\java.exe ch3p1
Process started >>>
Error: Could not find or load main class ch3p1
<<< Process finished.
I'm using Notepad++ and NppExec to compile faster, and I gave up trying to get it to run JRE v7 and just used the location of it. And here's my NppExec code (I don't know if it's important, but I'll post it anyways):
cd $(CURRENT_DIRECTORY)
javac $(FILE_NAME)
C:\Program Files\Java\jre7\bin\java.exe $(NAME_PART)
And, finally, here's the actual program I'm trying to get to run:
public class ch3p1
{
public static void main(String args[])
{
System.out.print("Hello.");
}
}
So, a quick recap. The first error I found out was because I was compiling and running a program with different versions of JDK and JRE. I couldn't figure out how to actually make it run with the JRE that came with my JDK installation so I used the direct path to it instead. My hopes got crushed that this would work when I went to run my compiled program. I got a simple "Error: Could not find or load main class ch3p1".
What's the question? I don't know exactly, the broad question is: What do I need to do to get this to work? I cannot be any more descriptive than that because I have no idea what to do or where to look next. I'm hoping I provided enough useful information and structured it well enough to make it comprehensible.
Some other questions: Will removing the two Java 6 updates in my Add/Remove Programs work? How do I change it so whenever it runs java, it'll run the 64bit JRE v7?
I have no idea what I'm doing here and I'm basically learning as I go. I am familiar with computers to an extent but I am new to Java and JDK so I don't know much about how it works. My leads might be completely misdirected and wrong, if so, please correct me.
EDIT
I understand that there are a lot of questions on this website and I'm sure the people posting here answer a lot of questions that can be solved with minimal to no effort involved. I have to say that I have looked everywhere and I came here to post this because I simply cannot find the solution to my problem. I wasn't looking for help on finding another program to use, and I definitely was not putting the files in my Java installation directory because despite me being new to Java, I am not new to programming. That response could have been easily avoided by looking at the first example I provided, and another one where the file path to my .java and .class files can be seen in a folder in my Documents.
I will list answers and what I have tried here:
I reinstalled JDK and JRE from the Oracle website
I have set my SET_HOME system variable and my Path system variable has the JDK bin directory in it.
My .class file and my .java file are in the same directory, and my class and the .java file are both named the same thing, including exact cases.
After I installed JDK and JRE I deleted my previous files and made a new one, and that didn't work either.
I tried putting the direct locations of java and javac as suggested in a reply.
I realize that there are better IDE and build programs out there, I am using javac because the class I am in right now is using javac.
Now, for some extra questions to help me out:
I have the Java v6.xx updates in my add/remove programs list, would removing these in any way effect anything in a positive or negative way. And would complete removal of all JDK/JRE files and re-installation change anything?
Is there any known issues with using Java and Windows 7 that I might be running into.
Is this an issue with JRE or JDK, because it seems to be compiling without any issues but when I go to run it is when I get the errors.
Are there any other variables other than CLASS_PATH or Path that I need to set?
I appreciate any and all help that's been given so far even though I haven't found a solution yet.
Try using the absolute path to the directory where you installed java. Here is what I would type on my machine
cd "C:\Users\Sean\Documents\JAVASTUFF\Chapter 3\1"
"C:\Program Files\Java\jdk1.7.0_02\bin\javac" ch3p1.java
"C:\Program Files\Java\jdk1.7.0_02\bin\java" ch3p1
if that works, you should add the directory to the path so that this is the preffered java version. This way you won't have to use the absolute path anymore and just type "java" and "javac" as usual
set PATH="C:\Program Files\Java\jdk1.7.0_02\bin\";%PATH%
Setting the path can also be done somewhere in the Control Panel so that you don't have to type that in each time you open a command prompt
Edit: You should probably set JAVA_HOME as well as "duffymo" suggests. If it still doesnt work there may be something wrong with your java installation. Try downloading and installing a new version from Oracle
Let's start by saying you should never, ever put any of your code in the directories where you installed Java JDK. Please make it a habit to create a separate folder (e.g. "c:\work") and put your project sub-folders there.
Open a command shell and type this: java -version. That will tell you the version of Java you're compiling and running with. You care about the JDK, because you're developing code.
Is your JAVA_HOME environment variable set? Please point it to the directory where you installed Java. Then add %JAVA_HOME%\bin to your PATH. If you do all this correctly, you should be able to compile in a command shell by typing javac.
So, create a folder c:\work\learning\src and put your ch3p1.java folder in it. Create a directory c:\work\learning\classes, too. Compile your code with this command:
javac -cp .;classes -d classes src\*.java
You should see ch3p1.class in the classes folder.
Run it with this command:
java -cp .;classes ch3p1
You'll see "Hello." in the console.
EDIT: I'd recommend that you read this tutorial carefully:
http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
You aren't the first person to compile and run "hello world". It seems to me that you're thrashing around too much. Simplify.
Several things here.
Java compiler can take a "target" argument to indicate for which Java version you wish to compile. By default, the target is the version of the current JVM.
So far, any class compiled with a given target is compatible with that target and any above version. So a class compiled for Java 5 is compatible with Java 5, 6 and 7.
To find out which version of Java you are running, type java -version in your terminal. It will output something like "Java 1.X..." The 'X' is the version of Java and you will often see people talking about Java 5 or Java 1.5 which is the same thing (same goes for 6 and 7).
The version that is running depends on several parameters, but usually it all comes down to the first Java bin directory in your 'PATH' environment variable.
Now, if you are considering Java IDE, there are 3 major ones:
Eclipse
NetBeans
IntelliJ
All three are fine Java IDE's and it is pretty much religious which one you will prefer. Personnally I use Eclipse.
Finally, for you problem:
Comiple using javac ch3p1.java
Run using java -cp . ch3p1
I know JMF is pretty much dead and whatnot, but I do know that it can still be used.
I intend to use it for personal uses and don't expect that much from it.
I have managed to install the 32bit JMF and when I run JMStudio it somehow magically works even though all of my java jres and sdks are 64-bit.
I personally believe that this proves that it CAN work.
When creating a program importing the jmf.jar as a library, my code compiles perfectly.
Only at runtime do i get any form of error with the common:
Exception in thread "VFW Request Thread"
java.lang.UnsatisfiedLinkError: JMFSecurityManager:
java.lang.UnsatisfiedLinkError: C:\Program Files
(x86)\JMF2.1.1e\lib\jmvfw.dll: Can't load IA 32-bit .dll on a AMD
64-bit platform
Obviously there is a problem with using a 32bit dll on a 64bit system.
My question is if its not compatible:
how does JMStudio work perfectly fine (it definitely uses java)
how can I fix it so that my program can run without depending on this dll
or other workarounds
Thanks a ton to anyone who has ever tried this before.
Java is definitely lacking in native specific tools such as webcams.
I think the main issue is the 64bit Java JRE/JDK trying to use the 32bit JMF, and/or JMF having a problem with the path that Windows 7 chooses as a default to install it to.
I have had success following the instructions posted here:
Oracle Forums: Install JMF on Windows 7 64bit
It basically boils down to:
Install a 32bit JRE/JDK, and ensure that this is what your code uses.
Install JMF to simple directory in the root of C: (i.e. c:\JMF2.1.1e)
Good luck!
JMFStudio is 32 bit supporting software so we must install 32bit support JDK and also Eclipse then we not get any exceptions as you mentioned in above and errors.
For my case it works fine.
and also
Try to remove unused jdk path in environment variable, if duplicate path present then also it not works fine
other wise you should re-install OS.