javax/inject/Inject.class in lib/javax.inject-1.jar is hidden by lib/javax.inject-2.5.0-b42.jar on onejar executable - maven

I am attempting to create an atomic executable jar (i.e. no dependencies outside of the jar).
To do this I have added a com.jolira:onejar-maven-plugin in my pom.xml. This seems to do the job, but when I execute the jar I get the warnings:
JarClassLoader: Warning: Null manifest from input stream associated with: lib/javax.inject-1.jar
JarClassLoader: Warning: javax/inject/Inject.class in lib/javax.inject-1.jar is hidden by lib/javax.inject-2.5.0-b42.jar (with different bytecode)
JarClassLoader: Warning: javax/inject/Named.class in lib/javax.inject-1.jar is hidden by lib/javax.inject-2.5.0-b42.jar (with different bytecode)
It seems that my dependencies are pulling in both javax.inject-1.jar and javax.inject-2.5.0-b42.jar. To verify this I checked and both have/are being downloaded from the repository. I certainly don't have both listed in the dependencies, so there must be some implied dependency AFAICS.
Anyone know if there is a way to exclude just one jar from a maven dependency, or alternately to prevent onejar-maven-plugin from including it in the executable jar?
Is there a better way to create an atomic (or some call them fat) jar where the java loader can actually load from an embedded jar. I've tried all day with various different recipes and onejar was the only one that actually got the loaded to work.

After some playing I found Alex's solution to be correct, just that I had put the exclude in the wrong place. The solution is to put it here:
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
<exclusions> <!-- exclude exclude javax.inject-1.jar -->
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>

Just putting this here for future.
I solved the problem in this way:
(It's for project's dependency which has javax.inject in its own dependencies)
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>

Related

Maven exclusions specific version into fat jar

I am working in project where Springboot jar and Hive jar creating conflict becuase of duplicate versions
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.0.3.1.0.0-78</version>
</dependency>
Above hive jar is fat jar and coming with many duplicate dependancy ,in following example you can see two versions 2.6.0 and 3.1.1.3.1.0.0-78
Now if we want to add exclude
<exclusions>
<exclusion>
<artifactId>XX</artifactId>
<groupId>YYY</groupId>
</exclusion>
</exclusions>
Now i want to exclude only 2.6.0 version and keep 3 3.1.1.3.1.0.0-78
, is there any option where we can defined excluded jar version ?
[WARNING]
Dependency convergence error for org.apache.hadoop:hadoop-auth:2.6.0 paths to dependency are:
+-com.syf.gemfire:jdbc-gemfire-dataloader-pcf:2.0.0
+-org.apache.hive:hive-jdbc:3.1.0.3.1.0.0-78
+-org.apache.hive:hive-common:3.1.0.3.1.0.0-78
+-com.github.joshelser:dropwizard-metrics-hadoop-metrics2-reporter:0.1.2
+-org.apache.hadoop:hadoop-common:2.6.0
+-org.apache.hadoop:hadoop-auth:2.6.0
and
+-com.syf.gemfire:jdbc-gemfire-dataloader-pcf:2.0.0
+-org.apache.hive:hive-jdbc:3.1.0.3.1.0.0-78
+-org.apache.hive:hive-service:3.1.0.3.1.0.0-78
+-org.apache.hive:hive-llap-server:3.1.0.3.1.0.0-78
+-org.apache.hbase:hbase-hadoop2-compat:2.0.2.3.1.0.0-78
+-org.apache.hadoop:hadoop-mapreduce-client-core:3.1.1.3.1.0.0-78
+-org.apache.hadoop:hadoop-yarn-common:3.1.1.3.1.0.0-78
+-org.apache.hadoop:hadoop-auth:3.1.1.3.1.0.0-78
and
+-com.syf.gemfire:jdbc-gemfire-dataloader-pcf:2.0.0
+-org.apache.hive:hive-jdbc:3.1.0.3.1.0.0-78
+-org.apache.hive:hive-service:3.1.0.3.1.0.0-78
+-org.apache.hive:hive-llap-server:3.1.0.3.1.0.0-78
+-org.apache.hbase:hbase-server:2.0.2.3.1.0.0-78
+-org.apache.hbase:hbase-http:2.0.2.3.1.0.0-78
+-org.apache.hadoop:hadoop-auth:3.1.1.3.1.0.0-78
To resolve the dependency convergence errors, add entries to <dependencyManagement>, in which you specify the version you want like
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.0.3.1.0.0-78</version>
</dependency>
Then all transitively found versions are replaced by the one you specified an the conflict is gone.

Maven same dependency on different scopes

I have a maven (3) project with multiple submodules. One on of them, I want it to explicitly depend on a dependency, without depending on its transitive dependencies. To do this, I'm using the folloing:
<dependency>
<groupId>org.example</groupId>
<artifactId>foo</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
This works as itended. During runtime, the transitive dependencies of "foo" will already be in the classpath, so everything goes well.
However, I need "foo"'s transitive dependencies for test. I tried to also declare a dependency of "foo" with scope test, but it seems that it conflicts with the one that excludes everything. It either works as expected in tests but fails in runtime, or vice-versa.
Do you known if something like this is possible with maven?
Of course it's possible, you need to declare 2 different maven profiles holding your dependencies.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Different dependencies for different build profiles in maven
You should check out Maven's <scope>import</scope> dependencies. Create a <profile/> for testing and define a dependency to a pom which contains these test dependencies you're interested in. (This might require some re-working of your pom.xml-s, but would be a good approach).
Check here for more details.

Spring Jar dependency Presedence

I have one Spring application(CustomerPort). In this I am using one open source jar(commons-lang.2.4). And my CustomerPort using other module, as jar, which using different version "commons-lang.2.2".
Since the other module using commons-lang.2.2, my application also refereeing modules opensource jar instead of commons-lang.2.4.
Could you plz let me how to exclude commons-lang.2.2 in Pom.xml file
use the <scope> tag to correct the scope of these transitive dependencies. Read this for more info on maven dependency scopes
In the pom.xml for CustomerPort, where you specify the dependency on the other jar module, you can specify an exclusion for commons-lang. This will prevent Maven from bringing in the commons-lang transitive dependency from the other jar.
<dependency>
<groupId>otherModuleGroupId</groupId>
<artifactId>otherModuleArtifactId</artifactId>
<version>otherModuleVersion</version>
<exclusions>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
</exclusions>
</dependency>
Verify that its doing the right thing by running mvn dependency:tree in CustomerPort.
More info on excluding transitive dependencies here

Prevent maven to copy dependencies to WEB-INF\lib folder

I have this dependency in the pom.xml:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.version}</version>
<scope>test</scope>
</dependency>
However although the scope is "test" the jars are still copied to the WEB-INF\lib folder:
src\main\webapp\WEB-INF\lib
I see 2 possible scenarios here.
1) These dependencies are somewhere referenced (directly or not) with compile or runtime scope besides their test-scoped use. Then, this wider scope is effectively used to satisfy all the needs about them.
2) You do (maybe unconsciously) some dependency processing hacking using Maven Dependency Plugin or stuff like that that do this mess.
And one issue at the end: I assume that this src/main/webapp/WEB-INF/lib directory is in fact empty (possibly doesn't even exist) and it's your mistake. As #Ryan said in his comment, all the libs (and any other build artifact) should land at target directory.

How do i use a "xxx-bin.tar.gz" file in a maven dependency?

i have some code that needs to work with the shibboleth codebase. The manual install steps i do are to download the shibboleth-identityprovider-2.3.5-bin.tar.gz, then extract it and do some tweaking and adding some jars that i build.
I want to do this in a maven assembly phase. However, since the binary has a "-bin" in it, i don't know what to specify in my pom.xml to download that file. In my pom i have:
<dependency>
<groupId>edu.internet2.middleware</groupId>
<artifactId>shibboleth-identityprovider</artifactId>
<version>2.3.5</version>
<type>tar.gz</type>
<exclusions>
<exclusion>
<artifactId>shibboleth-jce</artifactId>
<groupId>edu.internet2.middleware</groupId>
</exclusion>
</exclusions>
</dependency>
However, the dependency check fails (presumably because the tar file is named "shibboleth-identityprovider-2.3.5-bin.tar.gz" and not "shibboleth-identityprovier-2.3.5.tar.gz".
I'm not sure what i need to specify in my pom to use the proper tar file.

Resources