Exception java.lang.NoSuchMethodError on ExecutionStrategy constructor method - java

I am using GraphQL on a Java project and it was working on a server.
When I changed to another server, it stopped working and it is throwing the following exception:
java.lang.NoSuchMethodError:
graphql.execution.ExecutionStrategy.(Lgraphql/execution/DataFetcherExceptionHandler;)V
at graphql.execution.AbstractAsyncExecutionStrategy.(AbstractAsyncExecutionStrategy.java:19)
at graphql.execution.AsyncExecutionStrategy.(AsyncExecutionStrategy.java:23)
at graphql.GraphQL$Builder.(GraphQL.java:199)
at graphql.GraphQL.newGraphQL(GraphQL.java:166)
I am using exactly the same Java version (1.8.0_181), the same graphql-java dependency version (7.0) and the same project version.
Am I missing something? Anyone with the same problem?
Thanks in advance,
Solution
After analyzing the dependencies of each one of my project dependencies, I noticed graphql-java-annotations was importing version 3.0 of graphql-java library.
graphql-java library is one of my project dependencies as mentioned before (was using version 7.0).
As consequence, two different versions of graphql-java where being referenced and were conflicting with each other.
To solve this issue, I removed graphql-java dependency and I started using only the version imported on graphql-java-annotations.

Usually this is because dependency confliction.
You can add this to your pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
then try package your application, it will log which jar the graphql.execution.ExecutionStrategy class is loaded from. Then you can check if it is the correct version.

Related

Method introduced in java 9 is compiled using compiler target java 8

I'm experiencing an odd behavior in maven as well as in eclipse itself.
Even though i configured my project to be compiled in Java 1.8, I can compile and run (eclipse) a piece of code that was introduced in Java 9
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
The code line in question:
LocalTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId());
I'm using Oracle's JDK 11 locally for compiling and running in eclipse without any errors. When i package it into a docker container using openjdk:8-jdk-alpine it will boot up, but throw the following Exception when I call the method:
java.lang.NoSuchMethodError: java.time.LocalTime.ofInstant(Ljava/time/Instant;Ljava/time/ZoneId;)Ljava/time/LocalTime
How can I avoid and identify these situations before they go to testing? Am I doing something wrong or is it a bug in the build system or in JDK11?
thanks in advance
The source option specifies that the source code must be compatible with Java 8, the target option that the classes should be compatible with Java 8. However, you will still compile with the Java 11 class library if you build with Java 11 and then you can get errors like the one you have.
There are two good solutions. One is to use the Maven toolchains plugin and build with Java 8. Then you can have multiple Java versions installed and Maven will use the configured one on a per-project basis.
The other is to use the new release and testRelease options. They will build with API classes from the given release. Just add <release>1.8</release>.
If you are using JDK 11, configure your maven pom.xml like that:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
</plugins>
</build>

What's the difference between `spring-boot-maven-plugin` and `maven-compiler-plugin`?

I do not know the difference between spring-boot-maven-plugin and maven-compiler-plugin.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
Is that mean Spring Boot Maven Plugin's feature include maven-compiler-plugin?
I just use Spring Boot Maven Plugin is ok, do not need add 2 plugins??
"Spring Boot Maven Plugin provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application “in-place”."
"Maven Compiler Plugin is used to compile the sources of your project."
maven-compiler-plugin has two goals. Both are already bound to their proper phases within the Maven Lifecycle and are therefore, automatically executed during their respective phases.
compiler:compile is bound to the compile phase and is used to compile the main source files.
compiler:testCompile is bound to the test-compile phase and is used to compile the test source files.
To understand more about maven build lifecycle - http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
maven-compiler-plugin usages -
To compile source code using -source and -target javac Options
To compile source code using a different JDK
To compile source code using Memory Allocation Enhancement
To Pass Compiler Arguments
Most commonly used to define source and target versions.
Sometimes you may want to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. maven-compiler-plugin can also be configured to provide these options during compilation.
For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
or configure the plugin directly:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Technically we can use both spring-boot-maven-plugin and maven-compiler-plugin in combination if the requirement is to create an executable jar as well as make sure source and target code have a specific version (which is accomplished by including maven-compiler-plugin).
In my case, i didn't use in combination but when my java project is a spring boot app that needs to run as a micro-service etc then we need an executable jar as build output so used spring boot maven plugin (only) but my other java project that consists of spring beans or components and is going to be used as a spring enabled library in other external apps but not required to run on its own but had to make sure source and target versions are specified then normal "mvn package" generated jar should work. For that maven compiler plugin (only) should do the job.

Is it possible to create spring boot maven project with java 12?

I am trying to create web app using spring boot, maven and java 12. I started the project with spring-boot-starter-parent version 2.1.5.RELEASE, java 12 and maven-compiler-plugin version 3.8.1. I tried to run ./mvnw package but i got this error:
Fatal error compiling: invalid target release: 12
After that i wrote on the internet that maven compiler plugin uses old dependency for asm and i should specify new version of it. So i selected the latest version of asm which is 7.1 and i added configuration tag with properties release 12 and compilerArgs --enable-preview for java 12. The result was:
Fatal error compiling: invalid flag: --release
The next thing that i tried was to use spring boot starter parent version 2.2.0.M3 and to specify the repository to find milestone versions of spring from http://repo.spring.io/milestone. Unfortunately i got the same result. Any ideas?
Trying with previous versions to spring boot 2.2.0.MX it also failed for me, but I have managed to make it work with 2.2.0.M6 including some plugins and tweaking them to adapt with the preview features like:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<arguments>--enable-preview</arguments>
<jvmArguments>--enable-preview</jvmArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
This is now working with Java 13.

openshift: maven compiler error : Base64 can not find the symbol

I am deploying webapp to the openshift cloud.
While compiling the resources by maven automatically after deploying, it shows Base64: symbol not found
However when I maven compile it on my Pc, their are no errors and build is successfull. I tried to change Base64 from java.util to apache.commons.codecs. The error is still there while deploying and it successfully runs at my local machine
Following is the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
Should I place the commons-codec jar in WEB_INF directory. i read the solution somewhere but was not sure about it.
please suggest a solution. Thank you
</dependencies>
My guess is that you're using JDK 8 on your machine, but JDK 7 where the error is happening as java.util.Base64 is only available since Java SE 8.
I recommend to use the same Java version on both machines.
Otherwise you should consider cross-compiling. Just setting the source and target level is not enough, as you can see, as you're still able to call new APIs.

org/codehaus/plexus/archiver/jar/JarArchiver (Unsupported major.minor version 49.0) - Maven build error

Afternoon all,
I am receiving the above error when trying to build my project. I'm pretty sure this has something to do with Maven's latest update being compiled using Java 1.6 and the project we are trying to build is a 1.4 project. The plugin prior to this worked without problems, so I have added the following to the POM.xml file to try to force the existing plugin to be used.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.2</version>
</dependency>
But it continues to fail.
Any help would be much appreciated
Thanks
Try to add the following plugin for maven. It works for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
The error you are experiencing means that org/codehaus/plexus/archiver/jar/JarArchiver was compiled against Java 1.5 whilst you are trying to load using older Java version.
1.2 version of plexus-archiver works under Java 1.4. However 2.0 requires Java 1.5. Are you sure you are using 1.2?
If this is a plugin, it should be defined under <plugins>.
Use:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
I was getting this error till I changed my maven-source-plugin version to 2.2.1. I was getting the error with 2.1.1.
Including the 'old' version of a plugin in the pom.xml is solving part of the problem. you also need to make sure you are using the right jvm to match.
For a current project i'm working on I had to set JAVA_HOME to java 1.4 with maven 2.0.8. Problem with maven is that it looks for updates in the local and remote repositories (if there is a remote repository set in the maven settings.xml), than tries use version 2.5 for the 'clean' and 'install' plugins for example causing the major.minor 49.0 error (clean and install plugins version 2.5 are compiled with java 1.5 or greater while I tried to execute them in a java 1.4 environment).
With adding in the plugin snippet in the pom.xml of the project forcing it to use version 2.2 combined with the old java version on my path:
(set path=c:\youroldjavadirectory\bin;c:\youroldmavendirectory\bin) everything started working.
Check versions of java before running the maven command:
java -version
mvn -v
According to Fred from the m2e-mailing list, this has been fixed with m2eclipse-mavenarchiver 0.17.0. You can install it from http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.17.0/N/LATEST/
Just add the repo as an update site, and then upgrade the mavenarchiver component.

Categories

Resources