Quick answer
The quick answer is: you don't need to add other settings in pom.xml
(if you have no other requirements).
generate 3 files
You only need to generate 3 files (xxx.jar, xxx-sources.jar, xxx-javadoc.jar).
In the state of using the default value, you don't need to add any other additional settings.
Run Command:
mvn clean package source:jar javadoc:jar
Install sources and javadoc jar
Run Command:
mvn install:install-file \
-Dfile=Hello-1.0-SNAPSHOT.jar \
-DpomFile=pom.xml \
-Dsources=Hello-1.0-SNAPSHOT-sources.jar \
-Djavadoc=Hello-1.0-SNAPSHOT-javadoc.jar \
-DgroupId=org.example \
-DartifactId=Hello \
-Dversion=1.0-SNAPSHOT \
-Dpackaging=jar \
-Dclassifier=sources \
-DgeneratePom=true \
-DcreateChecksum=true
Example Project
Hello
├── pom.xml
└── src
└── main
└── java
└── org
└── example
└── Hello.java
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Hello</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Hello.java
package org.example;
/**
* Hello This is a demo class.
*/
public class Hello {
/**
* default constructor
*/
public Hello(){
}
/**
* echo Demo Method
* @param msg any string.
* @return Return the original parameter content you passed in.
*/
public String echo(String msg){
return msg;
}
/**
* hello Demo Method
* @param msg any string.
* @return Return "HELLO" plus the original parameter content you passed in.
*/
public String hello(String msg){
return "HELLO "+msg;
}
}
## generate 3 files
You only need to generate 3 files (xxx.jar, xxx-sources.jar, xxx-javadoc.jar).
In the state of using the default value, you don't need to add any other additional settings.
Run Command:
mvn clean package source:jar javadoc:jar
Install sources and javadoc jar
Run Command: Copy pom.xml
to target
dir
copy pom.xml targert/
target dir files
target
├── Hello-1.0-SNAPSHOT.jar
├── Hello-1.0-SNAPSHOT-javadoc.jar
├── Hello-1.0-SNAPSHOT-sources.jar
└── pom.xml
Run Command: install jar and source jar , javadoc jar to maven local repo (~/.m2
)
cd target
mvn install:install-file \
-Dfile=Hello-1.0-SNAPSHOT.jar \
-DpomFile=pom.xml \
-Dsources=Hello-1.0-SNAPSHOT-sources.jar \
-Djavadoc=Hello-1.0-SNAPSHOT-javadoc.jar \
-DgroupId=org.example \
-DartifactId=Hello \
-Dversion=1.0-SNAPSHOT \
-Dpackaging=jar \
-Dclassifier=sources \
-DgeneratePom=true \
-DcreateChecksum=true
(Ref: https://maven.apache.org/plugins/maven-install-plugin/usage.html )
Test Project - TestHello
TestHello
├── pom.xml
└── src
└── main
└── java
└── org
└── example
└── Main.java
pom.xml
ADD org.example Hello dependency
<dependency>
<groupId>org.example</groupId>
<artifactId>Hello</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Open TestHello in IDEA
then you can use Ctl+Q , show javadoc,
you can use Key F4 Jump to Source
.