JBMac
JBMac

Reputation: 339

How do I write a POM file for a jar for Maven Install?

I have a group of jars, yanfs.jar, yanfs-javadoc.jar, and yanfs-sources.jar. These are third party jars that Maven cannot resolve.

I have plan to use the Maven install command:

mvn install:install-file -Dfile=path -DpomFile=path

to add the jars to my maven repository so that I can use it in my code.

I just can't figure out how to write the pom file for the jar so the at least the sources jar is included along with the standard jar file.

This is what I have so far:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sun</groupId>
    <artifactId>yanfs</artifactId>
    <version>1.2</version>
    <description>Artifactory auto generated POM</description>
</project>

Does anyone else know what else I need to include?

Upvotes: 2

Views: 2727

Answers (3)

Archimedes Trajano
Archimedes Trajano

Reputation: 41630

I recommend to not bother creating the pom file, instead just let Maven install it for you and figure out the pom.xml for them.

One key property you want is classifier.

mvn install:install-file -Dfile=yanfs.jar -DartifactId=yanfs -DgroupId=com.sun -Dversion=0.0.1
mvn install:install-file -Dfile=yanfs-javadoc.jar -DartifactId=yanfs -DgroupId=com.sun -Dversion=0.0.1 -Dclassifier=javadoc
mvn install:install-file -Dfile=yanfs-sources.jar -DartifactId=yanfs -DgroupId=com.sun -Dversion=0.0.1 -Dclassifier=sources

Another approach that you can do in one line is to use the sources and javadoc properties:

mvn install:install-file -Dfile=yanfs.jar \
    -Djavadoc=yanfs-javadoc.jar \
    -Dsources=yanfs-sources.jar \
    -DartifactId=yanfs -DgroupId=com.sun -Dversion=0.0.1

The install:install-file page shows all the possible options.

Upvotes: 1

Trent Vigar
Trent Vigar

Reputation: 38

You might want to add a "build" section to your pom and include the maven-source-plugin[1] and maven-jar-plugin[2] with some configuration to your liking.

[1] https://maven.apache.org/plugins/maven-source-plugin/usage.html

[2] https://maven.apache.org/plugins/maven-jar-plugin/usage.html

edit : I misinterpreted your question, I was thinking you were trying to maven-ify these 3rd party dependencies by building them locally from source and building them with maven in order to generate the metadata you need for your project to consume. If these dependencies are open source, that is a potential option for your problem.

Upvotes: 0

Tunaki
Tunaki

Reputation: 137269

There's just no way you can know what to write here. The POM is a file that is bound to the project you are depending on. If this project did not distribute a POM file with it, you are probably out of luck. This file is supposed to contain all the transitive dependencies of the artifact but also a lot of other things like its licensing. You can't make that up.

You could take a look inside yanfs.jar to see if there's an embedded POM file in it. If there's one, it should be under META-INF/maven/{groupId}/{artifactId} and you don't need to tell the maven-install-plugin about it because it will find it automatically during installation:

If the JAR was built by Apache Maven, it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default.

Otherwise, there is really nothing you can do except letting maven-install-plugin generate a POM with the help of the generatePom attribute. Note that the POM you currently have was also generated, probably by your Artifactory server (given its content) when you uploaded it.

Concerning the other artifacts yanfs-javadoc.jar, and yanfs-sources.jar, you can tell the maven-install-plugin about them with the javadoc and sources attributes.

You would have the following command:

mvn install:install-file -Dfile=yanfs.jar -Dsources=yanfs-sources.jar -Djavadoc=yanfs-javadoc.jar

Upvotes: 1

Related Questions