I have a third party jar file that I have to use, but unfortunately it contains an embedded log4j configuration file as a resource. When I include the third party jar as a Maven dependency, I also pick up their log4j configuration, which overrides my own.
Is there a way to tell Maven to include a jar dependency, while excluding a specific resource within that jar?
The short answer is NO
But, if you wish to use your own log4j configuration set the System Property named log4j.configuration using -Dlog4j.configuration=somefile.properties or similar.
See this SO-answer for more info.
Yes, you can use maven shade plugin for that. You can use filters to exclude the resource.
A working example of how to achieve this:
<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>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Use
<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>
Related
I've been trying to run my Maven Kotlin Ktor project with command line. The project contains the MySQL configuration too. Every time I tried to hit the following command, I got the following error.
Here is my command.
kotlin -cp mysql-connector-java-8.0.30.jar:dev_meet_dev_api.jar MainClassKt
The dev_meet_dev_api.jar file is my project jar and mysql-connector-java-8.0.30 is for MySQL connection with the database. My project is dependent on MySQL connector that's why I added the external dependency for MySQL connector.
As soon I hit the above command on terminal I've got the following error.
Caused by: java.lang.ClassNotFoundException: java.sql.Driver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Edit 1: Added the maven file.
<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>spartons.com.devMeetdevApi</groupId>
<artifactId>KtorTesting</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version>1.7.10</kotlin.version>
<ktor.version>2.1.1</ktor.version>
<junit.version>4.12</junit.version>
<serialization.version>1.4.0</serialization.version>
<coroutines.version>1.6.4</coroutines.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>
<dependencies>
<!-- Kotlin language dependencies -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Kotlin's coroutines dependency -->
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>${coroutines.version}</version>
</dependency>
<!-- Ktor dependencies -->
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-jetty-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-content-negotiation-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-serialization-kotlinx-json-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-status-pages-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-cors-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<!-- Kotlin serialization version -->
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-json</artifactId>
<version>${serialization.version}</version>
</dependency>
<!-- MySQL connector dependency -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<finalName>dev_meet_dev_api</finalName>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
<args>
<arg>-opt-in=kotlin.RequiresOptIn</arg>
</args>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-serialization</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<excludes>
<exclude>mysql:mysql-connector-java:jar:</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
</project>
Edit 2: Added the java-11 modules
P.S I'm using Java 11. Projects works fine if I try to run with the IntelliJ.
You can do this directly in Maven! In your pom.xml add the driver as a dependency.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
Then you shade the dependency into the jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>mysql:mysql-connector-java</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Then directly execute the jar. If this does not help may I know which Java version you are using?
Kotlin applications need the Kotlin runtime to run (mainly kotlin-stdlib.jar). It can be included
in the application jar or not.
If the runtime is not included, you must add it to the classpath:
java -cp /path/to/kotlin-stdlib.jar:app.jar MainClassKt
You can also use the kotlin script, which automatically adds it:
kotlin -cp app.jar MainClassKt
In your case, the runtime is included thanks to the maven-shade-plugin, so you can run the app like this:
java -cp mysql-connector-java-8.0.30.jar:dev_meet_dev_api.jar MainClassKt
Possibility 1
It is possible that some dependency that you manually added has a different version of java.sql.Driver.
It is overriding the java.sql.Driver dependency version that your code flow needs.
To debug if this is actually the cause of your problem, you can use IntelliJ maven dependency plugin.
It can show if there is any conflict in dependency causing the needed class to not load.
https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#maven_dependency_diagram
Also, please note that in my experience, If multiple dependencies are loading different versions of same class, then you may get different results in different setup, since order of class loading may differ. This can result in your code working in IntellijIdea, but not when running from terminal.
Possibility 2
Check if the jdbc driver version is compatible with java and database versions that you are using. Try upgrading or downgrading the jdbc version to see if that resolves issue.
Debug approach 1: if above ways don't fix the issue
Since you say that your code works in Intellij, start your application in debug mode and put a debug point in java.sql.Driver.
See which the library which contains this class and the dependency which contains this library.
That can help you debug the cause of problem.
Debug approach 2: if above ways don't fix the issue
Use remote debugging.
Start your jar application in console with remote debug enabled.
Refer this on steps to do it.
https://www.jetbrains.com/help/idea/tutorial-remote-debug.html#ecd9fef1
Using this, you can find the code flow and the cause of problem for program that runs in console.
I hope that this helps you.
I looked around for a solution to this but could find anything reasonable. Most of them are related to JARs. I keep getting this frustrating error:
15-Jan-2020 11:36:06.605 SEVERE [Catalina-utility-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:269)
It comes from commons-logging.jar (1.2).
I have added my dependency, like:
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
The version comes from the parent pom.xml
I have these two plugins of note:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>pal-copy-dependencies</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<inherited>false</inherited>
<configuration>
<excludeScope>provided</excludeScope>
<excludeClassifiers>shared</excludeClassifiers>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
<silent>true</silent>
<useBaseVersion>false</useBaseVersion>
</configuration>
</execution>
</executions>
</plugin>
and
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultEntries>true</addDefaultEntries>
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathPrefix>WEB-INF/lib/</classpathPrefix>
</manifest>
</archive>
<attachClasses>true</attachClasses>
<classesClassifier>shared</classesClassifier>
<failOnMissingWebXml>true</failOnMissingWebXml>
<includeEmptyDirectories>true</includeEmptyDirectories>
<outputDirectory>${project.basedir}\lib</outputDirectory>
<webResources>
<webResource>
<directory>src/main/resources/ProcessOrderService</directory>
<include>*.*</include>
<targetPath>/ProcessOrderService/wsdl/</targetPath>
</webResource>
</webResources>
</configuration>
</plugin>
I don't know what I am doing wrong. The kicker is, when I put the commons-logging.jar in the Tomcat's lib folder, It works like a charm.
There is a dependency that I have in this war file:
<dependency>
<groupId>com.test.mypackage</groupId>
<artifactId>common-files</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
This also uses commons-logging, with the scope compile. But this dependency has to remain provided. Cant change that!
The only other dependency that might have caused a conflict or something was the activemq-core.jar but I added the exclusions parameter to it. But still didn't work.
Any help would be appreciated! Thanks!
Tomcat classloader considers the application local dependencies as last (https://tomcat.apache.org/tomcat-8.5-doc/class-loader-howto.html).
My best guess there is already this library (different version) somewhere in the Tomcat classpath (not surprisingly as it is an Apache logging library).
You can try to define the commons-logging as optional, it wont get transitively imported and will use whats available in Tomcat (assuming that version works fine with your code). Alternatively you need to find the library and replace/upgrade it.
I can package a JAVA project I've written. One which uses the Gson library for JSON features. I'm very new to JAVA so I could be making a dumb mistake but here's what I've assumed:
In the source code I have:
import com.google.gson.Gson;
and then use this import like so:
Gson gson = new Gson();
String json = gson.toJson(result);
In my Maven pom.xml I've included the following in the dependency section:
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
As I say, it does package to a JAR file with no errors (using Maven for packaging) but my JAR file is being used on AWS as a serverless function and so I believe what I need to do is include the Gson dependency as part of my JAR file (could be wrong). This seems to be backed up by the errors I get on AWS:
Having done some google searches it looked like maybe Maven's "shade" plugin might be the ticket. I added it into my pom.xml like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<artifactSet>
<includes>
<include>com/google/gson/**</include>
</includes>
</artifactSet>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
But looking in the generated JAR file I see no difference. What do I need to do to get this to work?
The full POM file can be found here: pom.xml
I'm unfamiliar with the shade plugin others have referenced. The way it sounds to me, you need an artifact that's an executable jar: a jar, with its dependencies.
Here's how I do that, using Maven:
<?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.company.groupId</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.company.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-source</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
What you want to pay attention to is the build plugin, maven-assembly-plugin. This tells Maven how to assemble/package the results of the build. In its configuration, you define the main class that contains the runnable application, which usually is going to be where your public static void main(String[] args) declaration is. You also define a descriptor-ref, which is a String that will be appended to the jar's name. So, you'd end up with artifactId-1.0.0-jar-with-dependencies.jar, using my POM as an example.
To further explain what's going on, without the changes I recommend, your POM is telling Maven to just build your code. As part of that, you declare dependencies, of which you have two right now: aws-lambda-java-core and gson. When you don't provide a scope, it defaults to compile scope. This tells Maven to grab that dependency when the program is compiled, so that the program can use that dependency's code. But, when packaging the build artifact of your program, Maven, by default, will not include those dependencies in the final jar; it expects that when you run the jar, you'll have those dependencies on your classpath.
By adding the assembly build plugin, you're changing those instructions to Maven. With that plugin, you're telling Maven that when it builds the program, it needs to assemble it in such a way that all declared dependencies are included (read: assembled) with the program, and to do that during the package phase of the build; you'll see these dependencies in the lib folder of the build artifact. And then, like I mentioned earlier, the descriptorRef is descriptive info that will be appended onto the build artifact's name.
As an aside, and not truly relevant to your question, I'd recommend looking into FasterXML for JSON handling and manipulation. So much more powerful, so much easier, and it's widely supported and used, which means it has a great community behind it.
If you have dependencies that will be provided from runtime container, you should set scope provided to these dependencies.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
And remove <artifactSet> section from plugin configuration, execute mvn package then jar with required dependencies will be created.
I referred so many links. I finally got this And I don't prefer this way
I want to exclude slf4j from this jar. It is glassfish embedded all.
Why do I want to Exclude?
It is a different story. If I include this slf4j, then AKKA event logging is not working due to multiple slf4j. If I exclude embedded jar completely logging works. But I need embedded jar but not glassfish slf4j.
Any Solution?
Glassfish' Pom. It seems slf4j is a transitive dependancy
Have you try something like:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0-b72</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
UPDATE
The slf4j classes are embedded. If you still want to work with an uber jar, an option is to shade glassfish-embedded-all, i.e. to create a maven project or a module with:
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0-b72</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/org/slf4j/**/*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and then to use the generated jar in place of glassfish-embedded-all.
I create my application archive with the maven assembly plugin.
All the dependency present in my pom are included without any problem.
Now I need to include two or more version of the same artifact.
If in my pom I put
<dependencies>
[...]
<dependency>
<groupId>db.test</groupId>
<artifactId>my-model</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>db.test</groupId>
<artifactId>my-model</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Of source the dependenvcy resolver remove the old version and only the 1.1.0 is packaged in the archive
I try to include the jar by using assembly xml descriptor file. And I didn't find any solution.
A possible solution will be to manually put all the needed model.jar inside a folder and tell the assembly to copy it in the archive. But I'm looking for a more configurable solution.
Any idea ?
I found a solution by using maven-dependency-plugin to copy resolved pom dependencies and additional jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
<execution>
<id>copy-model</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.test.pkg</groupId>
<artifactId>my-model</artifactId>
<classifier>server</classifier>
<version>1.0.3</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>my.test.pkg</groupId>
<artifactId>my-model</artifactId>
<classifier>server</classifier>
<version>1.1.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
Now I just have to add the following lines in my assembly xml
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/lib</outputDirectory>
<filtered>false</filtered>
<includes>
<include>*.jar</include>
</includes>
<fileMode>0600</fileMode>
</fileSet>
Maven assumes it doesn't make any sense to have more than one version of a module at once. It assumes that a newer version replaces the older version. If it doesn't it is not the same module. I suggest you give the newer module a different name and make sure it has different packages to avoid choising a random module.
In general Maven tried to encourage good application design and deliberately makes it difficult to do things it has determined to be a bad idea.
Another ugly solution might be to use WAR file overlays, exploiting the fact that this mechanism pays no attention to the versions of component JAR files when applying the overlays.
I agree, different versions means replacing the older one. If we have to consume two different versions of a webservice for some business requirement. It is a good idea to generate the stubs in different packages and while adding to maven you can specify different them in groupid. This should work.