I want to include a jar file in my build using maven - 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

Related

How can I include the jboss-client.jar present in the Wildfly bin/client folder to my maven project?

I have a maven project to which I have to add a external jar jboss-client.jar which is located in Jboss Wildfly 10 bin folder(bin/client). There is no version specified in the jar name.
When I add the jar manually in build path-it works fine.
However, since this is a maven project, I require a better way of doing this.
Note: The project works with only this jar and not other versions specified in pom.xml which I tried downloading.
Also, if I try to specify the external dependency in pom.xml, it asks for version of the dependency. However, I cannot specify the same as it is not mentioned in the jar.
My ultimate aim is to deploy this project in Jboss Wildfly 10.
Is there any other alternate way, I can add the jar?
Copy your jar to some other location and unzip/decompress it, then find Manifest file located at META-INF\MANIFEST.MF path.
Open it in text editor and look for Implementation-Version.
It will give you the version.
Reference
You can use maven to install third party library in local.
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Using below command you can install.
mvn install:install-file -Dfile=path-to-file/jboss-client.jar -DgroupId=org.jboss -DartifactId=jboss-client -Dversion=1.0

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.

Maven repository with a JAR and native dll's

I am writing a maven plugin to control another java program (jar). This jar needs two dlls in the same directory. I would like to install the jar and this two dlls as a maven repo into local .m2 dir or a maven repository server.
I have used following command to create the local repo for the jar within my project:
mvn org.apache.maven.plugins:maven-install-plugin:2.5:install-file -Dfile=protector.jar -DgroupId=com.protect -DartifactId=protector -Dversion=10.0 -Dpackaging=jar -DlocalRepositoryPath=lib
But now i do not know how i can get the dlls in the same dir like the jar file. If i use the above command then maven creates new folder for each dll and rename it.
Anybody knows a solution?

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

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.

How to install default jar file with maven-jar-plugin

Given a project with <packaging>something-not-jar</packaging>, how does one:
tell the maven-jar-plugin to produce the "normal" jar file and tell the maven-install-plugin to take that normal jar file and
install that to the local repository (in addition to the something-not-jar artifact that was produced)
If I tell the jar plugin to produce a test-jar, then it does that and the install plugin installs the xxx-0.0.1-SNAPSHOT-tests.jar to the local repo. But the "jar" goal apparently does not cause the resulting jar file to be installed in the local repo, even though the jar file is created in the target folder.
So how do I do this?
You should simply do the following:
mvn install

Resources