Java:以静态文件发布Maven开源库
【摘要】 发布开源库到Github
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:schema...
发布开源库到Github
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>com.mouday</groupId> <artifactId>hello-package</artifactId> <version>1.0-SNAPSHOT</version> <!-- 发布的软件包的位置 --> <distributionManagement> <repository> <id>local-repo-release</id> <name>GitHub Release</name> <url>file://${project.basedir}/maven-repo</url> </repository> </distributionManagement> <build> <plugins> <!--创建源码--> <plugin> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <phase>package</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!--创建javadoc--> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-javadocs</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
</project>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
构建功能
package com.mouday;
public class Hello { public void sayHello(){ System.out.println("Hello"); }
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
生成部署文件
mvn clean package deploy
- 1
生成如下文件
$ tree
.
├── README.md
├── hello-package.iml
├── maven-repo
│ └── com
│ └── mouday
│ └── hello-package
│ ├── 1.0-SNAPSHOT
│ │ ├── hello-package-1.0-20200731.025404-1-javadoc.jar
│ │ ├── hello-package-1.0-20200731.025404-1-javadoc.jar.md5
│ │ ├── hello-package-1.0-20200731.025404-1-javadoc.jar.sha1
│ │ ├── hello-package-1.0-20200731.025404-1-sources.jar
│ │ ├── hello-package-1.0-20200731.025404-1-sources.jar.md5
│ │ ├── hello-package-1.0-20200731.025404-1-sources.jar.sha1
│ │ ├── hello-package-1.0-20200731.025404-1.jar
│ │ ├── hello-package-1.0-20200731.025404-1.jar.md5
│ │ ├── hello-package-1.0-20200731.025404-1.jar.sha1
│ │ ├── hello-package-1.0-20200731.025404-1.pom
│ │ ├── hello-package-1.0-20200731.025404-1.pom.md5
│ │ ├── hello-package-1.0-20200731.025404-1.pom.sha1
│ │ ├── maven-metadata.xml
│ │ ├── maven-metadata.xml.md5
│ │ └── maven-metadata.xml.sha1
│ ├── maven-metadata.xml
│ ├── maven-metadata.xml.md5
│ └── maven-metadata.xml.sha1
├── pom.xml
└── src ├── main │ ├── java │ │ └── com │ │ └── mouday │ │ └── Hello.java │ └── resources └── test └── java
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
将代码推送到 Github,并开启Pages服务
仓库地址:https://github.com/mouday/hello-package
使用开源库
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>com.mouday</groupId> <artifactId>import-hello-demo</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <!--声明发布的Maven的repo地址--> <repository> <id>github-rich-repo</id> <name>The Maven Repository on Github</name> <url>https://www.pengshiyu.com/hello-package/maven-repo/</url> </repository> </repositories> <dependencies> <!--引入依赖--> <dependency> <groupId>com.mouday</groupId> <artifactId>hello-package</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>
</project>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
使用测试
package com.mouday;
public class demo { public static void main(String[] args) { Hello hello =new Hello(); hello.sayHello(); }
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
参考
https://www.liaoxuefeng.com/wiki/1252599548343744/1347981037010977
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/107710053
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)