java.lang.NoClassDefFoundError: jakarta/ws/rs/core/MultivaluedMap - java

I updated my project to Java 17/Wildfly 27/Keycloak 19 and I get the error:
java.lang.NoClassDefFoundError: jakarta/ws/rs/core/MultivaluedMap
The library Maven: jakarta.ws.rs-api is added in the library of the project via Maven: jakarta.ws.rs:jakarta.ws.rs-api:3.1.0
Does somebody know why this happens?
My pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>mainProject</artifactId>
<groupId>ch.company.mainProject</groupId>
<version>4.5.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>auth-post</artifactId>
<name>Project Auth Post (Keycloak Setup)</name>
<description>This project is responsible to setup Keycloak.</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>ch.company.project.AuthPostMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>ch.company.project.AuthPostMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ch.company.project</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client-jakarta</artifactId>
<version>19.0.0</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
</dependencies>
</project>
Stacktrace:
"C:\Program Files\ojdkbuild\jdk-17.0.2\bin\java.exe" -
Dtenant.config=../e2e-test/src/main/resources/e2e-config "-
javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.3\lib\idea_rt.jar=55918:C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.3\bin" -Dfile.encoding=UTF-8 -classpath C:\work\project\auth-post\target\classes;C:\work\project\common\target\classes;C:\Users\maku\.m2\repository\org\keycloak\keycloak-admin-client-jakarta\19.0.0\keycloak-admin-client-jakarta-19.0.0.jar;C:\Users\maku\.m2\repository\org\keycloak\keycloak-core\19.0.0\keycloak-core-19.0.0.jar;C:\Users\maku\.m2\repository\org\keycloak\keycloak-common\19.0.0\keycloak-common-19.0.0.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-client\6.2.2.Final\resteasy-client-6.2.2.Final.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-client-api\6.2.2.Final\resteasy-client-api-6.2.2.Final.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-core-spi\6.2.2.Final\resteasy-core-spi-6.2.2.Final.jar;C:\Users\maku\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-core\6.2.2.Final\resteasy-core-6.2.2.Final.jar;C:\Users\maku\.m2\repository\org\jboss\jandex\2.4.3.Final\jandex-2.4.3.Final.jar;C:\Users\maku\.m2\repository\jakarta\activation\jakarta.activation-api\2.1.0\jakarta.activation-api-2.1.0.jar;C:\Users\maku\.m2\repository\org\eclipse\angus\angus-activation\1.0.0\angus-activation-1.0.0.jar;C:\Users\maku\.m2\repository\com\ibm\async\asyncutil\0.1.0\asyncutil-0.1.0.jar;C:\Users\maku\.m2\repository\org\jboss\logging\jboss-logging\3.5.0.Final\jboss-logging-3.5.0.Final.jar;C:\Users\maku\.m2\repository\org\apache\httpcomponents\httpclient\4.5.14\httpclient-4.5.14.jar;C:\Users\maku\.m2\repository\org\apache\httpcomponents\httpcore\4.4.16\httpcore-4.4.16.jar;C:\Users\maku\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\maku\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\Users\maku\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\reactive-streams-1.0.4.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-jaxrs\3.15.3.Final\resteasy-jaxrs-3.15.3.Final.jar;C:\Users\maku\.m2\repository\org\jboss\spec\javax\ws\rs\jboss-jaxrs-api_2.1_spec\2.0.1.Final\jboss-jaxrs-api_2.1_spec-2.0.1.Final.jar;C:\Users\maku\.m2\repository\org\jboss\spec\javax\xml\bind\jboss-jaxb-api_2.3_spec\2.0.1.Final\jboss-jaxb-api_2.3_spec-2.0.1.Final.jar;C:\Users\maku\.m2\repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;C:\Users\maku\.m2\repository\org\jboss\spec\javax\annotation\jboss-annotations-api_1.3_spec\2.0.1.Final\jboss-annotations-api_1.3_spec-2.0.1.Final.jar;C:\Users\maku\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;C:\Users\maku\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar;C:\Users\maku\.m2\repository\com\github\stephenc\jcip\jcip-annotations\1.0-1\jcip-annotations-1.0-1.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-jaxb-provider\6.2.2.Final\resteasy-jaxb-provider-6.2.2.Final.jar;C:\Users\maku\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\4.0.0\jakarta.xml.bind-api-4.0.0.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\codemodel\4.0.1\codemodel-4.0.1.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\jaxb-core\4.0.1\jaxb-core-4.0.1.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\jaxb-jxc\4.0.1\jaxb-jxc-4.0.1.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\jaxb-runtime\4.0.1\jaxb-runtime-4.0.1.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\txw2\4.0.1\txw2-4.0.1.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\jaxb-xjc\4.0.1\jaxb-xjc-4.0.1.jar;C:\Users\maku\.m2\repository\org\glassfish\jaxb\xsom\4.0.1\xsom-4.0.1.jar;C:\Users\maku\.m2\repository\com\sun\istack\istack-commons-runtime\4.1.1\istack-commons-runtime-4.1.1.jar;C:\Users\maku\.m2\repository\com\sun\istack\istack-commons-tools\4.1.1\istack-commons-tools-4.1.1.jar;C:\Users\maku\.m2\repository\com\sun\xml\bind\external\relaxng-datatype\4.0.1\relaxng-datatype-4.0.1.jar;C:\Users\maku\.m2\repository\com\sun\xml\bind\external\rngom\4.0.1\rngom-4.0.1.jar;C:\Users\maku\.m2\repository\org\jboss\resteasy\resteasy-jackson2-provider\6.2.2.Final\resteasy-jackson2-provider-6.2.2.Final.jar;C:\Users\maku\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar;C:\Users\maku\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.4.2\jackson-databind-2.13.4.2.jar;C:\Users\maku\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.4\jackson-annotations-2.13.4.jar;C:\Users\maku\.m2\repository\com\fasterxml\jackson\jakarta\rs\jackson-jakarta-rs-base\2.13.4\jackson-jakarta-rs-base-2.13.4.jar;C:\Users\maku\.m2\repository\com\fasterxml\jackson\jakarta\rs\jackson-jakarta-rs-json-provider\2.13.4\jackson-jakarta-rs-json-provider-2.13.4.jar;C:\Users\maku\.m2\repository\com\fasterxml\jackson\module\jackson-module-jakarta-xmlbind-annotations\2.13.4\jackson-module-jakarta-xmlbind-annotations-2.13.4.jar;C:\Users\maku\.m2\repository\com\github\java-json-tools\json-patch\1.13\json-patch-1.13.jar;C:\Users\maku\.m2\repository\com\github\java-json-tools\msg-simple\1.2\msg-simple-1.2.jar;C:\Users\maku\.m2\repository\com\github\java-json-tools\btf\1.3\btf-1.3.jar;C:\Users\maku\.m2\repository\com\github\java-json-tools\jackson-coreutils\2.0\jackson-coreutils-2.0.jar ch.company.project.AuthPostMain
Fehler: Hauptklasse ch.company.project.AuthPostMain kann nicht initialisiert werden
Ursache: java.lang.NoClassDefFoundError: jakarta/ws/rs/core/MultivaluedMap

WildFly (and other JEE / Jakarta EE containers) provide their own Java EE / Jakarta EE classes (servlet API, JAX-RS, JPA, etc.). If you bundle them in your application, these classes will be not be used by WildFly. Even if the class files are identical, the classes in your application are not the same as the provided classes - they have different class loaders. Class equality does not just use the fully qualified class name, it also uses the class loader. As a result, you will most likely get a class mismatch. You didn't show the full stack trace, but this is a likely cause of it.
Mark these dependencies as provided, that should usually solve the issue. You will also have to do something in your shade plugin if they still get included.
The same goes for the RESTEasy dependencies, although that's specific to WildFly / JBoss.

Deleted .idea and reimported everything and now it works

Related

Incompatible class versions when submitting Flink a job

I'm trying to submit a streaming job using Beam 2.27/Flink 1.12, using the following Maven command-line:
mvn exec:java -Dexec.mainClass=org.example.MyPipelineClass -Pflink-runner -Dexec.args="--runner=FlinkRunner --flinkMaster=flink-host:8081 --filesToStage=target/pipelines-bundled-1.0.0.jar"
Things were working smoothly for a bit, but I recently made some edits and wanted to run a new version of the pipeline and am now getting the following error:
Caused by: java.io.InvalidClassException: org.apache.flink.streaming.api.graph.StreamConfig$NetworkInputConfig; local class incompatible: stream classdesc serialVersionUID = -3137689219135046939, local class serialVersionUID = 3698633776553163849
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:699)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1850)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2160)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1667)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:2093)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1655)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:503)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:461)
at org.apache.flink.util.InstantiationUtil.deserializeObject(InstantiationUtil.java:615)
at org.apache.flink.util.InstantiationUtil.deserializeObject(InstantiationUtil.java:600)
at org.apache.flink.util.InstantiationUtil.deserializeObject(InstantiationUtil.java:587)
at org.apache.flink.util.InstantiationUtil.readObjectFromConfig(InstantiationUtil.java:541)
at org.apache.flink.streaming.api.graph.StreamConfig.getInputs(StreamConfig.java:263)
... 21 more
My pom.xml looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>pipelines</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<beam.version>2.27.0</beam.version>
<flink.version>1.12</flink.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<maven-exec-plugin.version>1.6.0</maven-exec-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-shade-plugin.version>3.1.0</maven-shade-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-bundled-${project.version}</finalName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/LICENSE</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven-exec-plugin.version}</version>
<configuration>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>flink-runner</id>
<dependencies>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-flink-${flink.version}</artifactId>
<version>${beam.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>${beam.version}</version>
</dependency>
<!-- note that the pipeline runs on GCP -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>${beam.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-client-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- main output is JDBC/Postgres -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.4</version>
</dependency>
</dependencies>
</project>
Of course, before submitting the job I built the JAR using mvn clean package -Pflink-runner.
Flink is self-hosted on a GKE instance, and is deployed using the flink:1.12.4-java8 image.
I found this issue which seems to have the same error message, but no clear offender.
Any help or ideas to explore would be greatly appreciated, I have no idea what to investigate.
I found the issue own my own. In the pom.xml above, I specified that the Beam runner was beam-runners-flink-1.12, and the cluster was running Flink 1.12.4
Beam's Flink runner does not specify a patch, and uses Flink 1.12.0
Downgrading the cluster fixed my issue.

Akka missing Config Properties Akka.Version Akka.Stream

Packaging Akka application.
Hi I am trying to package my application into an executable Jar. Below is my Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.personalProjects</groupId>
<artifactId>MyAkkaProject</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>allinone</shadedClassifierName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>akka.Main</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream_2.12</artifactId>
<version>2.5.18</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream-kafka_2.12</artifactId>
<version>1.0-M1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.4.3</version>
</dependency>
</dependencies>
</project>
I can't seem to get the Jar to work, it states missing akka.streams config.
I went through the official doc here
but it doesn't seem to work.
If I copy all Jar to output directory everything works just fine but the issue seems to be when I try to create a big fat jar with all the dependencies in it.
my MANIFEST.INF is below:
Manifest-Version: 1.0
Main-Class: MyAkkaProject.App
where App is the class with psvm and MyAkkaProject` is the package name
I resolved the issue, the issue was my IDE when I ran he project or even build it, it wasn't using Maven Lifecycle commands and hence the plug-in wasn't getting triggered.

java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.<init>

I've been trying to debug this issue for a bit now, and searching SO and other websites I haven't been able to find a solution. I've checked all versions of the dependencies in my pom.xml and made sure they are compatible with grizzly2, and I've also verified that it is being imported. However, Java is still printing out this error upon run:
Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.<init>(Ljavax/ws/rs/core/Application;Lorg/glassfish/hk2/utilities/Binder;)V
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:334)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:122)
at com.kyrahosting.daemon.Main.startServer(Main.java:30)
at com.kyrahosting.daemon.Main.main(Main.java:34)
Here is my pom.xml:
4.0.0
<groupId>com.kyrapanel.daemon</groupId>
<packaging>jar</packaging>
<name>KyraPanel Daemon</name>
<artifactId>KyraDaemon</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-all</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<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>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.kyrahosting.daemon.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.17</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Any help will be appreciated!
Don't mix your Jersey versions
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25.1</version>
</dependency>
Which one is different? Fix it.
And get rid of this
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-all</artifactId>
<version>2.3.30</version>
</dependency>
jersey-container-grizzly2-http already pulls in everything you need for Grizzly.
As an aside, the error says nothing about "GrizzlyHttpServerFactory doens't exist". It's saying that there is no such method (in this case constructor)
public ApplicationHandler(Application application, Binder binder) {}
That's how you read this
java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.<init>(Ljavax/ws/rs/core/Application;Lorg/glassfish/hk2/utilities/Binder;)V
The reason you would get this error when mixing versions is because say some class in Jersey 2.25.1 is trying to call the constructor mentioned above. But in version 2.9.1 this constructor doesn't exist. Say it wasn't added til a later version. But when loading classes, the ApplicationHandler from 2.9.1 is loaded, instead of the one from 2.25.1. So now you have the wrong ApplicationHandler version loaded. Hence the error; there's no such constructor.
I was facing an issue similar to the one asked here with my Spring Boot Application. My application was unable to find LocalizationMessages class under org.glassfish.jersey.internal in place of org.glassfish.jersey.server.ApplicationHandler. with the same error java.lang.NoSuchMethodError .
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.LocalizationMessages.WARNING_PROPERTIES()Ljava/lang/String
2021-09-20 15:27:47.927 INFO 11 --- [http-nio-9070-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.glassfish.jersey.internal.LocalizationMessages.WARNING_PROPERTIES()Ljava/lang/String;] with root cause
The irony is that the same set of dependencies worked fine on a java maven project. On getting the dependency tree mvn dependency:tree for java project I was able to get class org.glassfish.jersey.internal.LocalizationMessages but it was missing on the dependency tree for Spring Boot Project.
Following Issues observed:
The Jar created by Spring Boot was not containing the dependency when I was using spring-boot-maven-plugin with version 2.4.3
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.3</version>
</plugin>
When I was trying to create a shaded jar with the above version then I was getting error for all the Transformer implementation I was using. Error ex: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ServicesResourceTransformer
I changed the version to 1.5.8.RELEASE and then the shaded jar compilation went through.
I replaced the default Spring Boot Application Plugin with the shaded jar Plugin.
Default Spring Boot Application Plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
<configuration>
<mainClass>com.rohit.agrawal.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Shaded Jar Plugin I used to resolve error
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
</dependency>
</dependencies>
<configuration>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.rohit.agrawal.Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
</plugin>
</plugins>
</build>
Please see that here spring-boot-version is 1.5.8.RELEASE
Now the Jar has the required class:
rohiagra-mac:faw-qa-api rohiagra$ jar -tvf target/faw-qa-api-1.0-SNAPSHOT.jar | grep "org.glassfish.jersey.internal.LocalizationMessages"
42097 Tue Sep 21 18:01:54 IST 2021 BOOT-INF/classes/org/glassfish/jersey/internal/LocalizationMessages.class
268 Tue Sep 21 18:01:56 IST 2021 BOOT-INF/classes/org/glassfish/jersey/internal/LocalizationMessages$1.class
1272 Tue Sep 21 18:01:56 IST 2021 BOOT-INF/classes/org/glassfish/jersey/internal/LocalizationMessages$BundleSupplier.class
In Dec.2017, this set of Maven dependencies worked fine for me to start Jetty with RS.
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.26-b03</version>
</dependency>

How to add resources to jar using maven shade plugin

My Project structure has resources folder inside the src/main/ folder. The resources folder contains the file server.properties. My pom is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fde</groupId>
<artifactId>Listener</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Listener</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate.version>3.6.10.Final</hibernate.version>
<java.version>1.6</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Hibernate dependencies START -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Hibernate dependencies END -->
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.fde.ListenerServer</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>resources</resource>
<file>server.properties</file>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The Jar is created properly and the main class is mentioned in the manifest. I have the following questions :
The target folder contains the classes folder whch has the class files. The jar also contains them so why are they needed. My goal is to have a executable jar with all the dependancies only.
The resources are not getting added in the jar at all. I have added the transformer according to instructions seen on the net but no use!!!
What are the other dir getting created in the target folder (maven-archiver, surefire, surefire-reports etc) ??
Another jar gets created every time i do a maven clean install (original-Listener....jar)
I have absolutely no clue about how to include resources. Any help is appreciated!!
EDIT:::
This is the tag i used for the maven-assembly-plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.fde.ListenerServer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
This created the Listener-1.0-SNAPSHOT-jar-with-dependencies.jar with all the classes from referred jars in the folders. The manifest also contains the main class.
The problem still is that I cant include the resource bundle in the folder \src\main\resources.
Also I cant understand why jar files referenced from my code are included in the jar as well as inside the META-INF folder.
The problem wasn't in your maven-shade-plugin's configuration, rather that you have explicitly set resource directory to a wrong path:
<!-- wrong -->
<resource>
<directory>resources</directory>
</resource>
As <directory> element's doc says: "Describe the directory where the resources are stored. The path is
relative to the POM."
So if you follow default maven project structure you have to set like this:
<!-- correct -->
<directory>src/main/resources</directory>
or don't set it, then it falls back to same as maven defaults.
I removed the following from the pom.xml and the property files were included at the root dir.
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<testSourceDirectory>src/test/java</testSourceDirectory>
Still havent figured out why there is a repetition of the referred classes in the jar.

How To: Eclipse Maven install build jar with dependencies

I am using Eclipse Maven (m2e) inside Eclipse and I am running my project like this:
My pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ro.project</groupId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ro.project</name>
<properties>
<org.springframework.version>3.1.1.RELEASE</org.springframework.version>
<org.hibernate.version>4.1.0.Final</org.hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>ro.project.ProjectServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7.0_02</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>ant-magic</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="test_classpath" refid="maven.test.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<ant antfile="${basedir}/clientExport.xml" target="export-all" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<artifactId>project-core</artifactId>
<url>http://www.project.ro</url>
</project>
After I run the maven install it is working...
Maven run configurations:
The problem is that my generated .jar it doesn't have the dependencies included....
How can I configure pom.xml to include all my dependencies in .jar format and not unpacked.. because it seems that unpacked are not working correct...
To be sure that including all jars is ok.. I downloaded and added each library into jar's /lib folder and the jar is running... so.. my only question is: How can I configure pom.xml in order to add all my dependencies in jar format?
I tried all methods:
assembly:assembly
assembly:single
assembly:single with my descriptor (an assemble.xml file) but it wasn't working
maven copy dependencies plugin but still not working with Eclipse Maven - m2e
I am out of solutions... can anyone tell me a proper way to add my dependencies in jar? I can't believe that maven is so complex and I can't find an answer to my question everywhere..
Thank you in advance
There are a couple of ways of doing this.
1) If you want an uber-jar (repacked with all dependencies), look into using and configuring the maven-shade-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.group.id.Launcher1</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
This will unpack all dependencies and merge them into one JAR file.
2) If you want to deliver a bundle (zip, tar.gz, etc) with the unpacked JAR files in the bundle (perhaps under lib/) then you need to look into the maven-assembly-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>create-distro</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dist.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note that this requires an assembly descriptor src/main/assembly/dist.xml and example looks like this:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>false</useTransitiveDependencies>
<unpack>false</unpack>
<scope>runtime</scope>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<outputDirectory>bin</outputDirectory>
<includes>
<include>com.group.id:project-launch1</include>
<include>com.group.id:project-launch2</include>
</includes>
</dependencySet>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>runtime</scope>
<fileMode>0644</fileMode>
<directoryMode>0755</directoryMode>
<outputDirectory>lib</outputDirectory>
<includes>
<include>com.group.id:project-lib1</include>
<include>com.group.id:project-lib2</include>
<include>com.group.id:project-lib3</include>
<include>com.group.id:project-lib4</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
And since you are now assembling dependencies, you have better define the dependency in the pom.xml, like so:
<dependencies>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>project-launch1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>project-launch2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>project-lib1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
... and so on ...
</dependencies>
3) If you are delivering a bundle with an executable JAR file launcher, you will likely need to add a maven-jar-plugin configuration in addition to the maven-assembly-plugin:
<dependencies>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>project-lib1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>project-lib2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>project-lib3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
... and so on ...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<compress>true</compress>
<manifest>
<mainClass>com.group.id.Launcher1</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Note that the "addClasspath" directive adds the project dependencies to the class path. This is needed for JAR launchers, as they explicitly ignore all CLASSPATH environmental variables.

Categories

Resources