maven-jar-plugin repository layout combined with maven-dependency-plugin - java

So I am using the maven jar plugin to copy my projects dependencies to a lib folder in the target folder.
I set the classpathLayoutType to repository (repository) since some of the dependencies have the same name.
The manifest now states something like this: lib/some/group/id/artifact/version/artifact.jar
However the maven dependency plugin, which I use to copy the dependencies to the lib folder does not follow this layout. It just copies the dependencies to the base of the lib folder. How can I change this behavior to match that of the jar plugin?

Assuming you are using the maven dependency plugin, and goal copy-dependencies setting useRepositoryLayout to true should do the trick

Related

How to add config files to a dependency jar to create target executable jar using maven

I need to create a "wrapper" project with a pom that pulls in a dependency jar file and adds some local config files to it (form src/main/resources) to create the target jar.
Can this be done using spring-boot-maven-plugin, maven-dependency-plugin, a combination of the two, or some other plugin entirely? (I have to use maven)
An example pom would be much appreciated.
Note: the dependency jar is built by a 3rd party as an executable jar (with transitive dependencies included) using spring-boot-maven-plugin. Likewise the jar I build must have the same main class and include all dependencies contained within the 3rd party jar.
Thanks in advance!

how can i copy multiple dependencies to multiple folders using maven dependency plugin

we are going with a ant-Maven configuration,
how i build the application : through ant's build.xml called from maven's ant-run plugin
what is needed to run build.xml: to have dependencies in a lib folder
issue faced : we have two folders for dependencies, which need to hold different dependencies, but dependency plugin will copy dependencies to only one folder.
how can i generate different dependencies to more than one folder ( lib and lib-external) .

Import external JAR Eclipse

I have a Maven project where I've imported an external JAR (via Build Path) and it's under Referenced libraries folder. How can I import it within my .java class file? I mean literally the code "import ??". The class is in com.example.demo package. Do I need to add a dependency somewhere (pom.xml)?
If that's a maven project the best way would be to add that jar as a dependency in your pom.xml dependencies section. Then when you compile with maven it will use that dependency. In order to build properly in eclipse you need to call mvn eclipse:eclipse and it will sync the dependencies in the pom.xml with the build paths of the eclipse project.
If the jar is not a common one and you cannot add find it in the public repo (for example some jar that you have created) then you need to first install it in your maven repository with the required group and artefact name. Otherwise if it is some library which is publicly available in the central maven repository maven will download the required jar and install it in your local repository for you

local dependency in my case

I am using maven to build my java project.
I have a library jar named my.jar used as my project's dependency. However, it is not available in the remote central repository. So, I would like to put the jar file under my project. So, I created a folder named my_repo/ under MyProject.
The directory structure of MyProject looks like this:
MyProject/
my_repo/
my.jar
pom.xml
But I have no idea how could I define my pom to find this particular dependency under MyProject/my_repo/my.jar ?
Could someone please help me for my scenario? By the way, I have also some other dependencies defined in my pom.xml, they are available in the remote central repo.
Using the system scope. ${basedir} is the directory of your pom.
<dependency>
<artifactId>..</artifactId>
<groupId>..</groupId>
<scope>system</scope>
<systemPath>${basedir}/my_repo/my.jar</systemPath>
</dependency>
The recommended way is usually to use a Maven Repository Manager (e.g. Nexus) and then deploy your library to this Maven Repository Manager.
See here for how to set up the settings.xml file:
http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html
How to create maven dependency for your local jars..
1)Create a maven project of the program of which you have to create the jar.
2)Add required groupid and artifact id and version no.
3)Then after writing the java files export it as a jar.
4)Now open other project in which you want to add local jar dependency.Go into its pom.xml and add dependency with the group id,artifact id and version which u had entered in the jar project.
5)Maven clean and install.Now that jar file will be available in your local repository. :)

How do I delcare a dependancy with artifactory

I'm new to artifactory and have just uploaded a bunch of custom jars to one of my repos. I now want to declare what dependencies there are between these jars so that when using gradle and specifying A.jar as a dependency it will transitively resolve B.jar as a dependency of A.jar but I cant find anywhere to say that A.jar depends on B.jar.
Please help
TIA
To get transitive dependency resolution, you'll have to upload a dependency descriptor (POM for a Maven repository, ivy.xml for an Ivy repository) for each Jar.
When you manually upload a Jar, Artifactory offers to generate a basic descriptor, which you can edit to fill in the dependency information.
When you build and publish a Jar with Gradle, Gradle will automatically generate and upload a descriptor containing dependency information according to the dependencies specified in the build script. If necessary, the generated descriptor can be further customized in the build script. See "8.6. Publishing artifacts" in the Gradle User Guide.

Categories

Resources