jar dependencies(available in the POM file ) are not added to the war file. - maven

I'm creating a base framework and distributing it as a jar file. Other developers will use this jar in the web application. others are going to use mvn install:install-file to install the jar in the local repository.
if i try to use the jar in the war , the jar dependencies(jar contains the POM file) are not available in the war. Then i included the pom file in the install command then it worked correctly.
mvn install:install-file -Dfile=path-to-file -DpomFile=path-to-pomfile
The jar file already contains pom file with dependencies,Then why do i need to include the pom file in the install command explicitly.
Is there any alternate ways to pull the dependency available in the jar(POM file) to the war file. otherwise unnecessarly i have to provide the jar and POM file to others.
Thanks,
Sampath

The war project should have its own POM file specifying a dependency on your jar project. In this way, when you build the war, your jar and all its dependencies would be pulled into the war automatically.
In order to distribute artifacts among your fellow developers you should install a repository manager, such as Nexus.

Related

Setting name of jar file while using mvn install:install-file

So previously I was trying to find a way to install jar file which is built in my project to the .m2 folder via run configuration support.
Link for reference.
My main concern then was to not keep any hard coded values in command and to pick most data from pom.xml file. This was achieved successfully, but now I have another problem.
In the project, I have 2 modules module1 and module2.
When module1 is built, it generates 2 files a war file since it is a web based application and second one is jar file which is used to satisfy dependencies of other modules.
The jar file is generated using
<attachClasses>true</attachClasses>
property set in the maven-war-plugin in pom.xml of module1.
So if the module1 artifact id is set as module1-corp, then the jar file is named as module1-corp-classes.jar if the jar is installed using maven-install-plugin. But due to the legacy structure of the project, maven-install-plugin cannot be used and I have to use maven command line via Intellij run configurations to install this file.
So the command I used is
mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar
This installs the jar file perfectly, only it doesn't append the classes part at the end of jar file. so my jar file is now installed as module1-corp.jar instead of module1-corp-classes.jar which is not working okay with modules which are dependent on it.
I suspect this is due to the way module1 dependency is accessed in module2 which is as follows:
<dependency>
<groupId>module1.groupid</groupId>
<artifactId>module1.artifactId</artifactId>
<version>${module1.version}</version>
**<classifier>classes</classifier>**
</dependency>
This code is in the module2 pom.xml. I believe the classifier part is what is causing the issue, but I cannot change this since it is a legacy project.
So in the end I have two options only
Rename the jar while it is being installed via maven command line
Some other way which can rename the jar via an Intellij run configuration.
I tried using following flag
mvn install:install-file -Djar.finalName=jarname
But this doesn't seem to work as expected.
The install maven plugin allows also to specify the classifier (see: here). So in your example the command would need to be changed to:
mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar -Dclassifier=classes

Upload multiple jar files to maven repository (e.g. Archiva)

In one of our project we are planning to generate multiple jar files (basically libraries, which contain no dependencies) .
We would like to upload these jar files to local maven repository (Archiva looks good, we are also open to other options) so other developers can simply use them.
(Single jar file deploy works great)
PS: We are using maven.
Thanks in advance.
When you build your jar files with Maven, you simply call mvn deploy (having a correct settings.xml) and the jar goes into your Maven repository.
If you have jars not built with Maven, you can use mvn deploy:deploy-file to upload them.

I want to include a jar file in my build using maven

The problem is like this
I have a maven build of my project already. But I have a requirement wherein I need to replace a .jar file located in WEB-INF/lib folder with another .jar file. This new jar file can be downloaded from a link.
What changes do I have to make in the pom.xml file to achieve this requirement. I tried to find out ways to do it but could not figure out the exact solution as I am a novice in Maven.
Assuming that the jar file is not found in any public maven repository you can install it in your local repository using the install plugin mvn install:install-file ... and refer it as any other dependency

Warning POM missing in the jar

I have created the jar through maven from some other project. The jar reside in the location repository. The jar contains the pom.xml file in META-INF/maven///pom.xml
and pom.properties.
I have also copied the pom.xml file while running the pom for that project using resource-copy
plugin. Still I am getting the below warning , there fore during the building of war the maven not able to include all the dependent jars of the above jars in the war file. Other option is to add thoses jars as a runtime dependency in my war pom file.
[WARNING] The POM for org.artifact:runtime.ui:war:1.0.0-SNAPSHOT is missing, no dependency information available
I found that only goal packaging will put the artifact in a local repository. But then for each artifact I need to do the install so that it will get in the files system repository with the pom file. Copying the pom file using resource plugin will not help.
Hi you need to install the specific jar to your local repository (for a start).
If this jar is properly packaged using maven you can issue the following command from the terminal:
mvn install:install-file -Dfile=<path-to-file>
If it is custom made you need to include the required parts like
mvn install:install-file -Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging
Please see the official documentation here.
Hope it helps

Maven: Deploying a jar/war with built in pom.xml file

I don't have a Maven project. What I have is a jar with the pom.xml embedded in the file. When I deploy this via the Artifactory GUI, Artifactory finds the pom and deploys it with the jar. It even recognizes the groupId, artifactId, and version.
When I try using mvn deploy:deploy-file it fails. If I extract the pom, and run mvn deploy:deploy-file with the -DpomFile=pom.xml, it works. Is there a way of deploying this jar with the embedded pom via the Maven command line? Or, do I need to extract the pom.xml first?
I have not heard of the possibility to specify the pom file from archive. I think it is unlikely to be an option, because Maven itself is just a light-weight program, which runs with plugins; and it needs some configurations to run with; and all references to plugins to be used are in those files.
Consider writing an Ant script that will extract the file, run mvn deploy:deploy-file -DpomFile=pom.xml and then delete the file.
The solution looks not very nice, I know, but it should help.
This is an Artifactory feature and not standard Maven behaviour.
Keep in mind that, for example, if you use dependency:unpack-dependencies or the assembly plugin to create some sort of über jar there would be multiple pom.xml files within the jar under the /META-INF/ path so it would be very difficult to select which pom was the true pom.

Resources