Maven: jars from zipped artifact as test dependencies - java

I have a project A that depends on a distribution of another project B. The distribution is a zip file which contains some resources and jars. It is contained as a .zip artifact in a maven repository.
I do not need the distribution of project B for compilation but for running tests for project A.
I use the dependency-plugin and the goal dependency:unpack to download and unzip the distribution.
1. Is there a possibility to get all .jar files contained in the .zip distribution in the classpath for the surefire plugin without naming every single jar explicitely?
2. If possible I also would like to include those jar files in the classpath of a eclipse project generated by the eclipse-plugin.

You can configure the classpath of the surefire plugin right? And of your eclipse project?
If so, you can use the maven plugin as shown here and filter to only copy jars and use the output directory that you configured in your classpath.
Does that answer your question?

Related

Java Maven -> quickls add folder of jars as depencency

my Java Project uses a "/libs" folder containing ~100 .jar files. Almost all of them are not in an official maven repository.
1.) In the moment I manually added to whole folder to the classpath with my Eclipse IDE. That enables to compile and run the App using the Eclipse IDE. But if I want to maven to compile and create jar-with-dependencies, maven of course does not know about the "/libs" folder.
2.) I know that I can add a jar file to my local maven repo with mvn install:install-file but this would take a very long time because I would also have to open every jar and find the whole package name to insert as '-DgroupId' and the Name of the Main Class to add as '-DartifactId'
3.) My Questions:
3.1) Is there an easy way to let maven just include all jars in a folder like I did with my Eclipse IDE? I know that would break the principle of maven that every jar is identified with group and artifact id, but it would be a quick solution.
3.2) If it is not possible to add a folder with jars as a dependency in maven, is there a faster way to add a jar file into a local repo. It would be easier if there is a maven command where groupId and artifactId are automatically discovered by the jar that I do not have to open every jar file and find the Main Class and its classpath
Quick answer: No.
In the past, I have written a script for that because there is not support in Maven for this.

Download jar with dependencies using Maven

I would like to use Maven to download a "fat" jar- one that includes all of its dependencies. (The same sort of jar that is built using the jar-with-dependencies descriptor Ref in the maven-assembly-plugin)
The default behavior of mvn dependency:copy is to download the jar and all of its dependencies in separate files. This is not what I want. I want the dependencies to be included in the jar itself.
How do I achieve this using Maven? If it's not possible, is there some sort of manual way of assembling the fat jar myself given all its dependency JARs?

What's the difference between Maven Jar Plugin and Maven Source Plugin?

I was reading about how to create a jar file with Maven, but I saw some pom.xml files using Maven Source Plugin and others using Maven Jar Plugin.
In the Apache Maven Project page I found these descriptions:
Apache Maven JAR Plugin
This plugin provides the capability to build jars. If you like to sign jars please use the Maven Jarsigner Plugin.
Apache Maven Source Plugin
The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.
Reading these descriptions, I stayed in doubt about when use one or other plugin, and what are the differences or benefits, because I understood that both make the same thing.
The Apache Maven JAR Plugin is used to build jar files containing .class files in order to distribute applications or libraries in bytecode format.
The Apache Maven Source Plugin is used to build jar files containing source files (.java files) in order to allow IDE to show the source code when debugging. This jar file is used in combination with the jar file containing .class files.
maven jar plugin
The jar plugin creates a JAR file from your Maven project. The jar goal of the jar plugin is bound to the package phase of the Maven default lifecycle. When you type mvn clean install, Maven will execute all the phases in the default lifecycle up to and including the install phase, which also includes the package phase.
maven source plugin
The source plugin creates a JAR file with the project source code. It defines five goals: aggregate, jar, test-jar, jar-no-fork, and test-jar-no-fork. All these five goals of the source plugin will run under the package phase of the default lifecycle.
Unlike any of the plugins we discussed before, if you want to execute the source plugin with the Maven default lifecycle, it has to be defined in the project POM file, shown as follows. The super POM file does not define the source plugin; it has to be within your Maven project itself
What is the Difference
Both create JAR files; however, the jar plugin creates a JAR file from the binary artifact, while the source plugin creates a JAR file from the source code. Small-scale open source projects use this approach to distribute the corresponding source code along with the binary artifacts.

How to use jenkins to take a module maven project and turn it into a .jar

So I'm working on a java project located here. I have it on a jenkins server and I want it to compile all the different modules under one jar. I tried copying what another project did but am unable to produce a jar so I believe it has something to do with how I need to configure jenkins in order for it to make the jar. The jar doesn't need to be executable.
The maven-assembly-plugin can create your jar: https://maven.apache.org/plugins/maven-assembly-plugin/usage.html
Your project has 4 JARs and they don't depend on each other.
If NameLayer depends on NameLayer1_8_R1 you have to
add the dependency NameLayer1_8_R1 to the pom.xml of NameLayer and
the maven-assembly-plugin as descrbibed here to create a fat JAR (including all depending JARs).
Do the first step for as many dependencies as you need.

What are the differences between Maven Jar Plugin and Maven Assembly Plugin?

Could somebody explain me the exactly differences between these two Maven plugins and when it is useful to work with one of these plugins?
Maven jar plugin simply creates a jar files with all SOURCE files [.class files compiled from .java files] packed in it. However, a jar itself cannot be deployed as it generally has dependencies on 3rd party jar files or other library jar files which are needed to execute SOURCE jar file.
This is where Maven assembly plugin comes into picture. It creates a package of an extension of your choice like .zip, .tar, .gz which is a fully deployable package with all dependencies packed in it. You can also specify directory structure in assembly plugin which should be created when package is deployed on server.
So a assembly plugin is always used in combination with jar plugin.
Maven Jar plugin provides the capability to build and sign jars.The plugin use Maven Archiver to handle jar content and manifest configuration.
Maven Assembly Plugin is used to create all assemblies.
For More Info visit- http://maven.apache.org/plugins/maven-jar-plugin/
http://maven.apache.org/plugins/maven-assembly-plugin/

Categories