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

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.

Related

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

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>

Maven leaves out a jar from WAR

We use maven 2.2.1 to build project. A master pom lists modules that are built (some WAR project and some "plain" JARs).
Recently we added a new dependency into one of the WAR projects:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.6</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>
When built locally from command line (mvn clean package) on a developers machine, it works fine. But when built on the automatic build system (by Hudson) the httpcore JAR (it is a dependency of httpclient) is not packaged into the final WAR. No error is reported, just the JAR is missing.
The maven settings.xml files are identical (except the repo path - the only noticeable non-default option is offline=true). What could be wrong?
The only thing that comes to my mind is that your build machine has old version of one of your modules in m2 repo.
Clear up whole $HOME/.m2/repository (or where you keep the repo) and try again.
Problem found. (and solved)
In short: the httpclient.jar in the repo was without its .pom file. (so maven did not know it had dependencies)
Long:
It is an offline repository, so missing artifacts must be fixed manually. The problem is I first copied the files to the wrong folder and maven did not "see" them. Then "blindly" followed its advice:
Missing:
----------
1) org.apache.httpcomponents:httpclient:jar:4.2.6
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.httpcomponents -DartifactId=
httpclient -Dversion=4.2.6 -Dpackaging=jar -Dfile=/path/to/file
That would just copy the jar file to the repo, without the pom.
So I just copied the complete folder for httpclient into the repo (and its parent and some other related files that maven then complained about).
It's a form of user error, I guess.

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

extra jar in war in a maven project

One business jar which have been developed by us is present in war. but I don't see in pom.xml.... when I search whole eclipse I found it is in .setting folder(.settings/org.eclipse.wst.common.component) of eclipse of same project.
here is entry of
<dependent-module archiveName="BankAccount-3.0.39.jar" deploy-path="/WEB-INF/lib"
handle="module:/classpath/var/M2_REPO/com/BankAccount/3.0.39/BankAccount-3.0.39.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
If you are sure that jar is not needed by your project, then run mvn dependency:tree and find the origin of the particular jar. Then you can exclude the jar by using
<exclusions>
<exclusion>
<groupId>Group Id</groupId>
<artifactId>jar which you want to exclude</artifactId>
</exclusion>
</exclusions>
under the particular jar through which it got bundled.
You can also remove the jar by using the <exclusion> tag in assembly.xml of the particular project
Do mvn dependency:tree and see how it works.

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.

Resources