In maven how to create jar where lib is outside? - maven

How do I configure my pom.xml so that maven generates a jar where the lib folder and all it's jars are a separate folder outside of my generated jar?

What you need here is to use :
Maven Jar Plugin to copy your generated jar to a different location you want.
Maven Dependency Plugin to copy your dependent jars to a location that you want.
You need to use the outputDirectory property in both the plugins to define the required location where you would like the jars to be copied to, respectively.
Here is an example of the configuration you would add in your POM.

Related

Sping Boot to generate jar with only class files and place dependency in a separate location

I would like to create jar's with only class files for my project and to copy all it's dependency into a separate folder and put these in docker.
You can copy all dependency into a separate folder using maven's copy-dependencies
Using maven configuration profile and exec tag's you can create jar's only with class files.
Use maven manifest tag in your pom.xml, So that you can add entries in your manifest files to locate where is the jar placed. So that when application boot's the jar will take dependency from that location.
While creating docker files, make sure to copy all the dependencies. You can use docker volumes

Include the bytecode of a JAR file in a gradle library vs. just adding it as a dependency

If I add a JAR file to a gradle project's depenencies, the code compiles just fine, but after publishing to maven (publishToMavenLocal), the classes from the JAR are not found.
Obviously, this is because the jar is added as a "dependency" and not part of the project itself. Is there a way to get the contents of the JAR file to merge into the library? Do I need to make a separate maven repo for each JAR?
You can always try to create a fat jar which includes dependencies. You can follow the instructions provided here https://www.baeldung.com/gradle-fat-jar

WildFly - Adding JARs to classpath

I am using WildFly 8.2.1.
I need to add specific JAR files to the class path. How can I do that?
Do I need to get inside the module hell?
All I need is to add a couple of extra Oracle JAR files to enable using TLS on the data source connection...
When you build your .war file, add them to the /WEB-INF/lib directory. They will be accessible on the classpath from there. In eclipse the eclipse maven plugin, m2e, will do it by reading your POM file, or of course, maven run by hand will do it.
In the POM file, have it packaged as a war
<packaging>war</packaging>
and declare your jar as a dependency.

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.

Include java webapp lib in maven build

I was having a dynamic webapplication created on eclipse. I converted it to a maven project using M2E plugin. I added maven war plugin in the pom.xml so that it can create war for my project using maven build.
But when I do the build, it fails to compile few classes which has reference to the jars of my webapp/Web-INF/lib folder. These jars I can't include as dependency in pom.xml.
How can I tell maven to include Web-INF/lib jars also while building classes and creating a war?
Its not correct way of doing this , you should not put any jar manually in WEB-INF/lib folder.
And if that jar is not available in MAVEN CENTRAL REPO , then you can download it and install it in your NEXUS CENTRAL REPO (if you have any) otherwise put that jar in your local maven repository and add it as a dependency in your pom file. If you don't want to include that jar in your WEB-INF/lib then change the scope to provided otherwise leave it as default i.e compile.
During build time MAVEN will look for that particular jar in your local repo first , and if it don't find it there then it try to download from Centra Repo.
Once it is available in your local repo , your build won't break.

Resources