Exclude javax.servlet package from com.google.gwt dependency on pom.xml - java

I use Vaadin 7, and vaadin have a default package javax.servlet and I need com.google.gwt in my dependencies which contains another javax.servlet. When I run my application I got this error :
SEVERE: Allocate exception for servlet Vaadin Application Servlet
java.lang.ClassCastException: com.vaadin.server.VaadinServlet cannot be cast to javax.servlet.Servlet
Now I want to exclude javax.servlet from this dependency, and here is what I tried so far :
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.6.1</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
and this :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<minimizeJar>true</minimizeJar>
<artifact>com.google.gwt:gwt-user</artifact>
<includes>
<include>com/google/**</include>
</includes>
<excludes>
<exclude>javax/servlet/**</exclude>
<exclude>javax/servlet/http/**</exclude>
<exclude>javax/servlet/resources/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
But both didn't work !. Help!

I think you actually want the gwt-servlet dependency rather than gwt-user.
That said, I don't know Vaadin; maybe there's a com.vaadin dependency that contains the GWT classes?

According to your 2nd try, exclude the required package in a way given below:
Example :
<configuration>
<packagingExcludes>
WEB-INF/lib/servlet-api*.jar,
WEB-INF/lib/jsp-api*.jar,
WEB-INF/lib/jstl-api*.jar,
</packagingExcludes>
</configuration>

Related

Excluding Classes using Maven Shade Plugin not working

The classes added to exclude in maven shade plugin don't get excluded.
My pom.xml has one dependency which has shaded classes conflicting with other dependencies.
So I added the path to those classes in maven shade plugin to exclude them.
I have this for maven shade plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</dependency>
</dependencies>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<excludes>
<exclude>io.confluent.shaded.kafka.serializers.subject.*</exclude>
<exclude>io/confluent/shaded/kafka/serializers/subject/*</exclude>
</excludes>
</filter>
</filters>
<mainClass>com.expediagroup.das.businessevent.CommerceBusinessBookingEventMetricCalculatorApp</mainClass>
<layout>JAR</layout>
</configuration>
</execution>
</executions>
</plugin>
After compiling it still shows those classes not being removed.
Any help is appreciated.

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

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

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>

Maven exec:exec - Need additional classpath elements for plugin

I'm using the maven exec plugin to run my project. My project has a Start class that uses embedded Jetty to run the app. The dependency in the normal part of the POM for jetty is marked as "provided" because I don't want it in the final WAR.
How do I tell the exec plugin to add the 2 jars below to the classpath when running mvn exec:exec? The executableDepedency elements do not add it to the classpath. Currently, the classpath is all of the dependency jars that are not marked test or provided.
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executableDependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
</executableDependency>
<executableDependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<version>${jetty.version}</version>
</executableDependency>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>net.mikeski.Start</argument>
</arguments>
</configuration>
</plugin>
Turns out there are 2 options that you can use with Maven when using exec:java (which is what I wanted). You can specify true/false for each:
use the project dependencies in the classpath
use the plugin dependencies in the classpath
So, I added my provided project dependencies as plugin dependencies and set both of the properties to true and it works.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<dependencies>
<dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<includeProjectDependencies>true</includeProjectDependencies>
<executable>java</executable>
<mainClass>com.whatever.Main</mainClass>
</configuration>
...

Exclude some classes via Maven build

I am converting a Gradle based Android project to Maven and have hit a speed bump when it comes to including the SimpleXML Framework.
In Gradle I can specify the following when importing the library:
compile('org.simpleframework:simple-xml:2.7.+') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
How can I do this in Maven please? I have tried using the Shade plugin but I think I made a mess of that. Here is my attempt:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>stax</exclude>
<exclude>stax-api</exclude>
<exclude>xpp3</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
I think what you want is described here:
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
Basically, within the <depdency> tag of the library where you want to exclude something, you add <exclusions>. Example from the link:
<dependencies>
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
Try using maven-compiler-plugin it works for me
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/src/main/java/*.java</exclude>
</excludes>
</configuration>

Categories

Resources