extra jar in war in a maven project - maven

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.

Related

Transitive Dependency How do i exclude. -- Maven

I have the below project structure under lib for project 2.
Project 2 (under lib)
- Maven dependencies (JARs)
- project 1 JAR (it has JARs in lib)
- Maven dependencies of project 1 (JARs)
I want to exclude all JARs under project 1 while preparing project 2.
I'm currently using the below in my POMs (both project 1 and project 2)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
When building project 1, I want it to build as an executable JAR with lib.
However when building project 2, I want project 1 as only a compiled JAR (meaning with only class files and not having lib (JARs)).
Project 1 is included as a normal dependency in Project 2. Can anyone help me out?
If you want to exclude all dependencies of a given dependencies, use exclusions
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
and do it like
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Of course, you have to be sure that the missing transitive dependencies are not needed at runtime.
If I understand correctly project 1 builds a jar which has inside a lib directory with the dependencies.
You could in project 1 have 2 assembly executions, one the basic jar and another with dependencies and execute manifest, normally you use a different "classifier" for multiple artifacts of the same project.
Otherwise you would need to "repackage" the jars to remove the libs you don't want using some plugin like Shade.
I think the first option is much better, also by default if you publish it to a repository both jars will be published so other people can get one or the other.

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.

Excluding transitive dependency not working

Project A references Project B. Project B has included a local dependency. This local dependency unfortunately has a dependency to net.java.dev.designgridlayout in version 1.5.
We want to use net.java.dev.designgridlayout in version 1.11 in Project A but we are not able to "overwrite" the dependency. Eclipse always uses the dependency from Project B.
We already tried to exclude the 1.5 version from the local dependency, but it doesn't work.
The strange thing is, that Eclipse successfully resolves a class that has been added with version 1.11. For an already existing class, however, eclipse resolves it from the transitive dependency from de.someCompany.
Project B:
<dependencies>
<dependency>
<groupId>de.someCompany</groupId>
<artifactId>fs-client</artifactId>
<version>5.1.209</version>
<exclusions>
<exclusion>
<groupId>net.java.dev.designgridlayout</groupId>
<artifactId>designgridlayout</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.java.dev.designgridlayout</groupId>
<artifactId>designgridlayout</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
Project A:
<dependencies>
<dependency>
<groupId>Project-B</groupId>
<artifactId>Project-B</artifactId>
<version>1503.01</version>
</dependency>
</dependencies>
I also tried to include the 1.11 dependency in Project A.
We even tried to install the DesignGridLayout V. 1.11 in the local dependency and to change the groupID and artifactId to something different, but it cannot even be found by Eclipse for some reason. If it would be possible to include the DesignGridLayout with another groupId and artifactId, I think it would work.
mvn install:install-file -Dfile=lib\designgridlayout.jar -DgroupId=com.company.designgridlayout -DartifactId=design-grid-layout -Dversion=1.11 -DgeneratePom=true -Dpackaging=jar -DlocalRepositoryPath="%USERPROFILE%\.m2\repository"
Not sure - but:
Your project A has a dependency to itself? Shouldn't it use project-b?
Its not a good idea to change group or artifact id's as maven can no longer detect its the same artifact. If you do a custom version the version number should be enough.
If you add the dependency in your own pom then you don't need to exclude the artifact, since the groupId and artifactId are the same. The version in your own pom will win in project-b. If project a defines that dependency again itself that version will win.
I would do a mvn dependency:tree on project-a pom to see where the dependencies come from.
For eclipse: it indexes the local repository. In the maven settings there is a re-index button. So if you manually copy jars in there that may help eclipse to find the artifact. But that workaround would need to be done on every machine. I would not count that as solution. In the maven world artifact-resolution is an infrastructure issue and should not be handled per project. The way this is done should be transparent through the settings.xml

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

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