Enable Swing when compiling with javac

I compile and the jar source is just fine, but when I run it, it complains:

java.lang.ClassNotFoundException: javax.swing.JPanel

I think I should include the Swing library when compiling, but how do I do this?

I have included each rt.jar in my system:

 javac -classpath /usr/lib/jvm/java-1.5.0-gcj-4.4/jre/lib/rt.jar:/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar:/home/me/equinox.jar *java 

It still compiles fine, it still crashes on startup.

+4
source share
4 answers

It looks like you are using GCJ . This is an old project that tried to create a Java implementation as pure open source.

They got about half, but the implementation is far from ideal. These days, it's best to avoid this and use OpenJDK (or Oracle / Sun JDK if open source is not a requirement) instead.

On Ubuntu, you can use update-java-alternatives to tune your system to a different Java implementation:

 sudo update-java-alternatives -s java-6-openjdk 

By the way, you never need to explicitly point rt.jar to your classpath, as it is always available automatically. Also, using multiple rt.jar from different JVMs is a recipe for disaster.

+2
source

If you run the code, compilation works fine. It is strange that you are missing this particular class, since it is part of the standard library. On most Java distributions, this is in the rt.jar file

0
source

What is your current JDK path (in $ PATH or% PATH%)? What is your way? What is the current CLASSPATH environment variable? Your problem is with the runtime. You should not add rt.jar to your classpath. If you have the proper JVM installation installed, java does not need a location for rt.jar and tools.jar. I suspect you have problems starting the JVM.

Also, what is the command line that you use to run the program?

0
source

You do not need to include rt.jar, it is included in the default class loader java vm.

You need to find out which version of java is standard:

 java --version 

if you use ubuntu, most likely it will be openjdk java, and that’s fine. If it is gcj, try running it using openjdk or sun-jdk.

Also show how you run the jar.

0
source

Source: https://habr.com/ru/post/1339120/


All Articles