When trying to use GraphicsBuilder, I get a java.lang.NoClassDefFoundError for groovy.swing.factory.BindProxyFactory.
This is my environment:
% java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
% groovy --version
Groovy Version: 1.5.7 JVM: 1.6.0_10
% ls ~/.groovy/lib/graphicsbuilder*
graphicsbuilder-0.6.1.jar
...
And this is what I try to do:
% groovysh
Groovy Shell (1.5.7, JVM: 1.6.0_10)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------
groovy:000> import groovy.swing.SwingBuilder
groovy:000> import groovy.swing.j2d.GraphicsBuilder
groovy:000> import groovy.swing.j2d.GraphicsPanel
groovy:000> def gb = new GraphicsBuilder()
ERROR java.lang.NoClassDefFoundError: groovy.swing.factory.BindProxyFactory
at groovysh_evaluate.run (groovysh_evaluate:5)
...
Where is BindProxyFactoryBean?
It's in the Groovy 1.6 builds, not the 1.5.7 builds. Apparently GfxBuilder 6.1 was built against the Groovy 1.6 codebase.
Yes, that is correct. Groovy 1.6.x is required for GfxBuilder 6.1 and onwards.
Related
I've got a weird issue with Java 11. I'm porting a huge project, and I have some tests which use DecimalFormat failing on the 11 build, but not on the 8 build.
DecimalFormat in Java 11 gives me a comma decimal separator, and on Java 8 it gives me a dot.
Here is a minimal reproducible example:
import java.text.DecimalFormat;
public class Test {
public static void main(String[] args) {
DecimalFormat format = new DecimalFormat("#0.00");
System.out.println(format.format(1.02));
}
}
which outputs 1.02 on Java 8, and 1,02 on Java 11.
Here is the entire terminal session of building and running the example with both versions:
~ » sdk use java 8.0.282.hs-adpt
Using java version 8.0.282.hs-adpt in this shell.
~ » javac -version
javac 1.8.0_282
~ » javac Test.java
~ » java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)
~ » java Test
1.02
~ » sdk use java 11.0.10.hs-adpt
Using java version 11.0.10.hs-adpt in this shell.
~ » javac -version
javac 11.0.10
~ » javac Test.java
~ » java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
~ » java Test
1,02
Has anyone had similar issues? Were there any changes to relevant classes between 8 and 11 which would cause this?
Yes, one of the changes was updating Locale Data to Unicode CLDR v33 (see https://www.oracle.com/java/technologies/javase/jdk-11-relnote.html)
This change is relevant for locale-specific formatting, which impacts the usage of the utils like DecimalFormat or SimpleDateFormat.
So if your code depends on locale-specific formatting, you should double check it after switching to Java 11.
We are facing this error since migration from OpenJDK 8 to OpenJDK 11.0.9 from openjdk:11-jdk-slim.
java.lang.NoClassDefFoundError: Could not initialize class sun.font.SunFontManager
at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:265)
at java.desktop/sun.java2d.SunGraphics2D.getFontMetrics(SunGraphics2D.java:869)
$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment 18.9 (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9.1+1, mixed mode)
Similar issue has been registered on RedHat here: http://bugzilla.redhat.com/show_bug.cgi?id=1768935
However, as far as I understand, we are not using JDK from RedHat source code (even if openjdk-11 project is built and packaged by them, before being used by AdoptOpenJDK project....).
As a workaround, we moved to Amazon Coretto 11 which is currently based on following version.
$ java -version
openjdk version "11.0.9.1" 2020-11-04 LTS
OpenJDK Runtime Environment Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS, mixed mode)
No errors.
What worked for me with openjdk:11-jdk-slim docker image was to install fontconfig
and to add --add-exports java.desktop/sun.font=ALL-UNNAMED to the jvm parameters. E.g.:
ENV JAVA_OPTS="-server --add-exports java.desktop/sun.font=ALL-UNNAMED"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS /app.jar" ]
I have some Java code that compiles on my Mac, but fails to compile on my Ubuntu machine. Specifically, when using the static of method of List, I get the error:
error: cannot find symbol
List<String> list2 = List.of("cat", "dog");
^
symbol: method of(String,String)
location: interface List
1 error
I thought perhaps this was an issue with the Java version. Sure enough, it was using only Java 8. However, I subsequently upgraded my Ubuntu machine to use Java 11 using OpenJDK, but I still get the same issue.
The output I get from running java -version on the Ubuntu machine is:
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment (build 11.0.1+13-Ubuntu-3ubuntu116.04ppa1)
OpenJDK 64-Bit Server VM (build 11.0.1+13-Ubuntu-3ubuntu116.04ppa1, mixed mode, sharing)
The output I get from running java -version on the Mac machine is:
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
For compilation, I am using Gradle version 5.2.1. I am using the Gradle wrapper, so both machines are using the same version of Gradle.
Here is the file that does not compile properly.
package mypackage;
import java.util.List;
import java.util.ArrayList;
public class App {
public static void main(String[] args) {
// No errors on both MacOS and Ubuntu
List<String> list1 = new ArrayList<>();
list1.add("cat");
System.out.println(list1);
// Fails to compile on Ubuntu
List<String> list2 = List.of("cat", "dog");
System.out.println(list2);
}
}
List.of() was introduced in Java 9. This indicates that your update from Java 8 to Java 11 wasn't successful.
Run ./gradlew -v to see which version of Java is resolved by Gradle:
------------------------------------------------------------
Gradle 5.3.1
------------------------------------------------------------
Build time: 2019-03-28 09:09:23 UTC
Revision: f2fae6ba563cfb772c8bc35d31e43c59a5b620c3
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Linux 4.15.0-47-generic amd64
Make sure you aren't using Gradle daemon started on Java 8 before updating to Java 11 and in build.gradle force Java 11 compatibility:
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Everyone!
I have a java program with jar libraries that works on the following JDK version:
java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
I need to make it compile on a supercomputer that works on the following JDK version:
java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
As you can see they all have the same JDK which is JDK 8. However, when compiling using:
javac myFile.java
The following error appears:
class file has wrong version 51.0, should be 48.0
It seems that the compiling is done on another JDK (other than 8). Can anyone please help me solve this problem?
Kindest Regards!
java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.
J2SE 8=52,
J2SE 7=51,
J2SE 6.0=50,
J2SE 5.0=49,
JDK 1.4=48,
JDK 1.3=47,
JDK 1.2=46,
JDK 1.1=45
First Rule: Java version must be same on your local pc and server. Otherwise this kind of unwanted problem may arise.
For more checking, You can check
java --version
javac --version
It will make clarify of jdk and jre version mismatch. If it shows various version, then uninstall other versions and build your project and deploy on server.
Another answer is similar to your problem is here: Cannot compile Java code - "class file has wrong version 52.0, should be 48.0"
Resource Link:
Exception in thread “main” java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0
I was running a geoscript-groovy tutorial code:
groovy:000> import geoscript.layer.GeoTIFF
groovy:000> format = new GeoTIFF()
groovy:000> raster = format.read(new File("raster.tif"))
, and got the follow errors:
ERROR java.lang.NoClassDefFoundError:
javax/media/jai/ImageLayout
I have limited knowledge about JAI. I don't know whether this is a general JDK configuration issue or an issue with groovy etc.
My questions are:
What's the cause of this error associated with javax.media.jai.ImageLayout and how to fix it?
How do I verify if javax.media.jai.ImageLayout is really installed.
Thanks
P.S. The software environment is Ubuntu 12.04 with:
$java -version
java version "1.6.0_32"
OpenJDK Runtime Environment (IcedTea6 1.13.4) (6b32-1.13.4-4ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
$groovy -v
Groovy Version: 1.8.6 JVM: 1.6.0_32 Vendor: Sun Microsystems Inc. OS: Linux
-- UPDATE --
I changed JDK to oracle
$ java -version
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
and still I am getting the following error:
ERROR java.lang.NoClassDefFoundError:
javax/media/jai/ImageLayout
at org.geotools.gce.geotiff.GeoTiffFormat.getReader (GeoTiffFormat.java:287)
at org.geotools.gce.geotiff.GeoTiffFormat$getReader.call (Unknown Source)
Also, the commands I used to install Oracle JDK are:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
I also did
sudo apt-get install libjai-core-java libjai-imageio-core-java
and I am still getting the same error.
To use javax.media.jai.ImageLayout you need an Oracle JDK. It's not present in OpenJDK. I don't know the library you're using so I can't tell you if there is any option to e.g. inject different strategy for image manipulation. Switch to Oracle JDK and test if it works for you that way.