I upgraded to maven 3. My projects are built using jdk6, so eclipse JRE points to java 6 home.
It appears that maven 3 requires java 7.
My JAVA_HOME points to java 7, but Maven plugin apparently uses JRE 6 (Eclipse JRE), and throws this exception when run from eclipse:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
How can I let m2eclipse use java7 (which is my JAVA_HOME)?
Note that standalone maven works properly, but it's easier to run it from eclipse.
set M2_HOME to you maven home, set JAVA_HOME, then set you path so at the beginning is
Path=%JAVA_HOME%/bin;%M2_HOME%/bin
If you're on windows this is set by start->right click on computer, properties->advanced system settings->environment variables.
You also need to change you eclipse to use the java 1.7 jdk. That should take care of things, you can set the compile level in your eclipse/maven project to 1.6.
I were facing same issue with eclipse. Adding below plugin to plugins list and rebuild project using Alt+F5 solved my problem. Hope it will solve yours as well :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<debug>true</debug>
<verbose>true</verbose>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
</configuration>
</plugin>
After rebuild eclipse will automatically select JRE1.7 if you have JRE1.7 configured in eclipse preferences.
Related
I have downloaded Spring Tool Suite4 IDE, Java17 Came Along with that IDE. But i want to work on Java8.
I installed only java8 in my system and started working on to print just "Hello Spring Boot".
When i run the sample project the code is being compiled with java17 and trying to run with java8(which i have given in execution environments and build path)
I got error like below.
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at com.aditya.springboot.HelloSpringBootProjectApplication.main(HelloSpringBootProjectApplication.java:10)
I changed the compiler compliance from 17 to 1.8 in windows-\>preferences-\>Compiler-\>JDK Compliance..,
I pointed the Installed JREs to from jre 17(default) to jdk 1.8 and
I changed the compiler compliance from 17 to 1.8 in project-\>properties-\>java compiler also.
I tried uninstalling the STS4 and reinstalling it, but still i am getting same error.
As i am using maven project i tried changing \<java.version\> to 1.8 from 17 in pom.xml file too.
Can anyone help me from where STS is taking java17 inorder to compile my code, i haven't installed java17 in my system also. I have pointed JAVA_HOME in enviroment variables(user level variable but not system level varaiable) to java8 only.
I think you might need to adjust your pom.xml if you are using it to configure the java version. However, you need to make sure that the spring boot version that you are using is compatible with java 8.
In your pom.xml add the following:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version> // your spring boot version
</parent>
............
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source> // the version you desire
<target>1.8</target> // the version you desire
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
for gradle:
plugins {
java
}
group = "com.group"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8 // desired version
java.targetCompatibility = JavaVersion.VERSION_1_8 // desired version
I found an answer
The problem is with java version in pom.xml file of Maven:
If i am creating a maven project with spring boot version 3+, pom.xml is taking java version as 17 by default. Even if we change the version to 1.8 in pom.xml it is showing error as version mismatch because pom.xml internally taking java17. When i changed the java version to 9 in pom.xml it compiled and ran successfully. so we need to use java9+ for spring boot 3+.
But still i want to use java 1.8 for project so i degraded springboot version:
For creating the same maven project i used spring boot version 2+(i.e 2.7.8).
Now maven by default took 1.8 version with out giving chance for us to modify.
My project ran with 1.8 successfully.
I've started getting a rather cryptic error in one of my tests. Surefire report is as follows:
-------------------------------------------------------------------------------
Test set: de.systel.streckenmatching.GeoCoordinateTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.129 sec <<< FAILURE!
de.systel.streckenmatching.GeoCoordinateTest Time elapsed: 0.128 sec <<< ERROR!
java.util.ServiceConfigurationError: sun.util.locale.provider.LocaleDataMetaInfo: Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:584)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:856)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1078)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1301)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1386)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:176)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:279)
at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:250)
at java.base/java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:180)
at java.base/java.util.Formatter.getZero(Formatter.java:2437)
at java.base/java.util.Formatter.<init>(Formatter.java:1956)
at java.base/java.util.Formatter.<init>(Formatter.java:1978)
at java.base/java.lang.String.format(String.java:3302)
at org.junit.runner.Description.formatDisplayName(Description.java:114)
at org.junit.runner.Description.createTestDescription(Description.java:86)
at org.junit.runners.BlockJUnit4ClassRunner.describeChild(BlockJUnit4ClassRunner.java:96)
at org.junit.runners.BlockJUnit4ClassRunner.describeChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:352)
at org.junit.runners.ParentRunner.run(ParentRunner.java:359)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.LinkageError: loader 'platform' attempted duplicate class definition for sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo. (sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo is in module jdk.localedata of loader 'platform')
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1109)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:780)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:701)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:582)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:634)
at java.base/java.lang.Class.forName(Class.java:505)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:854)
... 40 more
Caused by: java.lang.LinkageError: loader 'platform' attempted duplicate class definition for sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo. (sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo is in module jdk.localedata of loader 'platform')
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1109)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:780)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:701)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:582)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:634)
at java.base/java.lang.Class.forName(Class.java:505)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:854)
... 40 more
The test itself is absolutely nothing special, just validating equals for some POJO classes:
public class GeoCoordinateTest {
#Test
public void test() {
GeoCoordinate coord1 = new GeoCoordinate();
coord1.setLatitude(5.0);
coord1.setLongitude(10.0);
GeoCoordinate coord2 = new GeoCoordinate();
coord2.setLatitude(5.0);
coord2.setLongitude(10.0);
GeoCoordinate coord3 = new GeoCoordinate();
coord3.setLatitude(5.1);
coord3.setLongitude(10.0);
assertEquals(coord1, coord2);
assertNotEquals(coord1, coord3);
}
}
It happens under OpenJDK 14:
...>java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
I am puzzled. What is happening and how do I fix this?
I had this happen when I was upgrading from Java 8 to Java 11 while running the test with JetBrains' IDE Intellij IDEA.
What was happening in my case was that the Project SDK was different from the one being used by the 'platform'.
In my case, the platform was Gradle's JVM. If anyone comes across this, know that you can set up the Build Tool to match the Project SDK by going to Preferences > Build, Execution, Deployment > Build Tools. Here you have options for Gradle or the question's Maven, among others.
The same happened to me when I was upgrading from JDK11 to JDF15. This problem appears at JDK14+, but is fine at JDK13.
This problem occurred to me in an automated test project with JDK 15, TestNG, mongo-java-driver, Selenium, and other dependencies.
I had to upgrade to JDK 15 due to a bug in the mongo-driver with JDK 13. After this update, the error "Unable to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo" started to occur.
I solved it with the maven settings that I put below.
<properties>
<jacoco.version>0.8.6</jacoco.version>
</properties>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I had the exactly the same issue with Java 8, Eclipse 2021-03 (refreshly installed).
Apparently Eclipse comes with its own JRE, and Gradle will use it as default.
To fix the issue, you need to go to Preferences > Gradle and manually change Java Home to match your default/system/project Java Home.
So, the software is working properly and everything is fine. I did find some answers to my question online but I can't seem to fix my problem. Everything seems to be okay in my Build Path and in order.
The error I'm getting:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.hibernate.service.ServiceRegistry
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I need to export my project to a JAR file, please help me, I'm desperate. And thanks to anyone that cares to answer in advance.
Building a jar-with-dependencies will solve your problem.
Add the following to your pom.xml file:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.main.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Run mvn clean compile assembly:single
Then you will be able to run java -jar name-with-dependencies.jar
So, I've figured out what was the problem. The problem was, I was using Java 8 for my project while I had installed (some time ago) Java 9 on my PC. When I tried to run the JAR file, it used Java 9 to run it and it had some dependencies misplaced. I just uninstalled Java 9, exported the project with jre 1.8.0_144 and I'm running jdk 1.8.0_121 on my PC. Everything works great now.
Thank you #Gal and #AJNeufeld for your answers and your help.
I'm trying to use db2triples for the first time, which is a java / maven project.
I got information about it from its github page.
So far, I have performed the following steps:
cd /programs/db2triples-master
vim pom.xml and added the db2triples dependency
mvn compile
mvn package
mvn dependency:copy-dependencies
java -cp target/dependency/*.jar:target/db2triples-1.0.3-SNAPSHOT.jar net.antidot.semantic.rdf.rdb2rdf.main.Db2triples
And I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
at java.lang.Class.getMethod0(Class.java:3010)
at java.lang.Class.getMethod(Class.java:1776)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
After googling around, this may be a classpath error, but I'm not sure. What needs to be done in order to run this application?
The error means that when you run db2triples, it can't find a dependency that is needed.
One way to resolve this problem is to add the required dependencies to your class path. Is the apache commons cli jar actually sitting in target/dependencies?
Another way to resolve this is to build a jar that has all the dependencies embedded. The assembly plugin as a jar-with-dependencies descriptor. Add this to your <build><plugins> section in your pom.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorId>jar-with-dependencies</descriptorId>
</configuration>
</plugin>
To build it mvn assembly:assembly.
You should have another jar sitting in targets named something like db2triples-<version>-jar-with-dependencies.jar. Then to run the application, you just need to run java -cp dbp2triples-<version>-jar-with-dependencies.jar net.antidot.semantic.rdf.rdb2rdf.main.Db2triples
According to your linked github page, you should get the required dependencies
Needed dependency
OpenRdf Sesame > 2.6.x - http://www.openrdf.org/
Commons-cli > 1.2 - http://commons.apache.org/cli/
Commons-logging > 1.1.1 - http://commons.apache.org/logging/
Or, if you're using maven, add db2triples as a dependency to your pom
<dependency>
<groupId>net.antidot</groupId>
<artifactId>db2triples</artifactId>
</dependency>
I am a java beginner.
I am trying a Java program in a unix system.
I am getting the below error
Exception in thread "main" java.lang.ClassNotFoundException: com.sybase.jdbc.SybDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at reportToCSVg.main(reportToCSVg.java:13)
I know that in eclipse i can just add the jconn.jar to make it work. please advise me the equivalent i need to do such that whenever i run the program in the server, i had included the jar file which is in a another path
you can set the classpath as follow: http://www.ehow.com/how_4784820_set-classpath-eclipse.html
and put your jar file in your projects classpath .
or you can put your jar file as
Select the library and click "Edit" (left side of the window)
Click "User Libraries"
Select the library again and click "Add JARs"
http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
You can use Maven to package your -jar file containing all the dependencies if you are using Maven.
If you are using plain Eclipse with Ant -Just use the Fat-jar Plugin.
For Maven add the assembly plugin to pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>app.runner.Runner</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
For the Maven goal use the below -
maven assembly:single