GitHub建立个人Maven仓库

摘要:
github添加远程发布插件yoursettingnamecom.github.githubsite-maven-plugin0.9maven-pluginmvncleandeploy运行结果手动上传到github发现github上并没有上传文件,于是新建了一个branch并上传。###在项目根目录上面cd./target/mvn-repo#进入mvn包目录gitinit#初始化本地仓库gitadd.#添加文件gitstatus#查看状态gitcommit-m"maven仓库"#提交到本地#关联到服务器,并没命名仓库为origingitremoteaddoriginhttps://github.com/AutKevin/maven-repo.gitgitbranchrepo#创建repo分支gitbranch-a#查看所有分支gitcheckoutrepo#切换到repo分支gitpushoriginrepo#推送到origin远程仓库的repo分支maven包上传到服务器格式如下,在maven-repo仓库下的repo分支中。

Maven

官网:https://maven.apache.org/repository/index.html

一、配置github

设置登录名name

在github的个人设置中,设置好自己的姓名 。这个环节很重要,若不设置姓名,会出现一些一些意想不到的错误。maven的setting中的配置文件用户名都用这个。

GitHub建立个人Maven仓库第1张

二、生成maven包到本地

修改pom文件发布到本地仓库

在需要发布的项目中的pom文件中的build -> pluginManagement -> plugins标签下加入以下插件:

<!--编译本地仓库包插件,生成target/mvn-repo下面-->
<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.1</version>
    <configuration>
        <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
    </configuration>
</plugin>

GitHub建立个人Maven仓库第2张

然后运行 mvn clean deploy 命令,即可在对应项目中的target/mvn-repo目录下找到本地的jar。

三、发布到github(失效)

修改mvn配置文件settings.xml

Win+R输入%MAVEN_HOME%打开maven安装目录,修改本地maven的配置文件settings.xml,找到其中的servers 标签,加入如下 配置:

<server><id>github</id><username>github登录名</username><password>github登录密码</password>
</server>

修改pom文件properties中添加下列属性

关联setting.xml中使用哪个github的server。

<github.global.server>github</github.global.server>

添加远程发布插件

            <!--发布到服务器插件,需要依赖上面的部分-->
            <!--查看aliyun的仓库https://maven.aliyun.com/mvn/search,发现需要依赖包-->
            <plugin>
                <groupId>com.github.github</groupId>
                <artifactId>site-maven-plugin</artifactId>
                <version >0.9</version>
                <configuration>
                    <message >Maven artifacts for ${project.version}</message>
                    <noJekyll>true</noJekyll>
                    <outputDirectory>${project.build.directory}/mvn-repo</outputDirectory><!--本地jar地址-->
                    <branch>refs/heads/master</branch><!--branch必须是refs/heads/开头的,后边跟分支名称-->
                    <merge>true</merge>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <repositoryName>maven-repo</repositoryName> <!--对应github上创建的仓库名-->
                    <repositoryOwner>your setting name</repositoryOwner> <!--github仓库所有者setting中的name-->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>site</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>

依赖插件

        <!--发布到服务器插件的依赖包 -->
        <dependency>
            <groupId>com.github.github</groupId>
            <artifactId>site-maven-plugin</artifactId>
            <version>0.9</version>
            <type>maven-plugin</type>
        </dependency>

mvn clean deploy运行结果

GitHub建立个人Maven仓库第3张

手动上传到github

发现github上并没有上传文件,于是新建了一个branch并上传。

### 在项目根目录上面
cd ./target/mvn-repo   #进入mvn包目录
git init   #初始化本地仓库
git add .   #添加文件
git status   #查看状态
git commit -m "maven仓库"  #提交到本地  
#关联到服务器,并没命名仓库为origin
git remote add origin https://github.com/AutKevin/maven-repo.git  
git branch repo    #创建repo分支
git branch -a    #查看所有分支
git checkout repo    #切换到repo分支
git push origin repo    #推送到origin远程仓库的repo分支

maven包上传到服务器格式如下,在maven-repo仓库下的repo分支中。依然读取不到。

GitHub建立个人Maven仓库第4张

四、发布到ftp服务器(能发不能读,需和http服务器联用)

通过插件

官网:https://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html

pom.xml中添加

<project>...
  <distributionManagement>
    <repository>
      <id>ftp-repository</id>
      <url>ftp://repository.mycompany.com/repository</url>
    </repository>
  </distributionManagement>
 
  <build>
    <extensions>
      <!--Enabling the use of FTP -->
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-ftp</artifactId>
         <version>1.0-beta-6</version>
      </extension>
    </extensions>
  </build>...
</project>

setting.xml文件中配置

<settings>...
  <servers>
    <server>
      <id>ftp-repository</id>
      <username>user</username>
      <password>pass</password>
    </server>
  </servers>...
</settings>

然后执行mvn deploy

通过idea的Deployment

Setting -> Build,Execution,Deployment -> Deployment

GitHub建立个人Maven仓库第5张

设置好要上传的文件夹

GitHub建立个人Maven仓库第6张

上传成功如下:

GitHub建立个人Maven仓库第7张

报错500 Illegal PORT command

GitHub建立个人Maven仓库第8张

点击Advanced Options,勾上Passive mode

modprobe ip_nat_ftp
modprobe ip_conntrack_ftp

使用ftp发现能上传成功却不能读取。找不到原因。。。欢迎指教~

GitHub建立个人Maven仓库第9张

五、通过tomcat发布

在webapp下面新建一个mvn文件夹,把项目发布到mvn项目下即可。

手动部署

在项目的pom.xml中添加:

<distributionManagement>
    <repository>
        <id>file-repository</id>
        <url>file://D:mvn-rpo</url>
    </repository>
</distributionManagement>

运行mvn deploy命令可以看到在D:abc目录下生成了目录和各种文件。将整个目录上传到Tomcat的webapps/mvn下面。

ssh自动部署

官方文档:https://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ssh-external.html

<distributionManagement>
    <repository>
        <id>ssh-server</id>
        <url>scp://ip/home/java/apache-tomcat-8.5.5/webapps/mvn</url>
    </repository>
</distributionManagement>

<build>
    <extensions>
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh-external</artifactId>
            <version>1.0-beta-6</version>
        </extension>
    </extensions>
</build>

新建一个用户:https://www.cnblogs.com/aeolian/p/12449679.html

Maven的settings.xml中配置服务器的SSH用户名和密码:

<server>
    <id>ssh-server</id>
    <username>root</username>
    <password>your-password</password>
</server>

执行mvn deploy

idea的Deployment(推荐)

使用idea的ftp发布,首先要建一个ftp用户并给用户指定文件夹赋予权限。

#进入到webapp目录
cd /usr/local/tomcat/apache-tomcat-7.0.54/webapps
#新建mvn文件夹
mkdirmvn 
#给mvn文件夹赋给ftp用户mvn
chown mvn:mvn mvn

然后用mvn用户名登录

GitHub建立个人Maven仓库第10张

GitHub建立个人Maven仓库第11张

点击Tools -> Deployment -> Browse Remote Host,进行upload。

六、GitHub Package

官网:https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages

生成Token

点击右上角头像,点击Setting -》Developer settings -》Personal access tokens,写上备注,勾上权限。点击生成后一定要先复制Token,下次就不显示Token了。

GitHub建立个人Maven仓库第12张

Maven的Setting配置

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <!--读取mvn库用,选择要激活的profile -->
  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>
  <!--读取mvn库用,配置一系列profile,一定要写到具体仓库 -->
  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <!--上面两项也可以不配置,只不过每次都要在pom.xml文件中配置,这里配置可以一劳永逸 -->

  <!--发布读取都要用到 -->
  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN,注意这里是Token不是你的密码啊啊啊啊啊啊啊</password>
    </server>
  </servers>
</settings>

Pom.xml

<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
   </repository>
</distributionManagement>

执行mvn deploy,注意!!!一定要把maven-deploy-plugin这个插件给注释掉,不然只会发布到本地,不会执行发布到远程服务器。

如果报错,可以使用mvn -e deploy或者mvn -X deploy查看详情。

GitHub建立个人Maven仓库第13张

一直报Return code is: 401, ReasonPhrase: Unauthorized,检查了setting中的server配置的用户名密码正确,一天后发现password需要填的不是密码是token。

七、使用仓库

github package

在需要使用jar包项目的pom文件中添加github仓库,也可以在maven的setting中配置profile。无论哪种一定要用server的用户名和token。

    <!--引入仓库-->
    <repositories>
            <repository>
                <id>github</id>
                <name>GitHub autumn Apache Maven Packages</name>
                <url>https://maven.pkg.github.com/AutKevin/maven-repo/</url>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
    </repositories>

然后执行mvn install。

tomcat

tomcat的端口/项目名

        <repository>
            <id>tomcat-repository</id>
            <url>http://52zt.info:88/mvn</url>
        </repository>

添加依赖

<dependency><groupId>com.autumn</groupId><artifactId>aeo-tool</artifactId><version>1.0.0</version>
</dependency>

参考:https://www.jianshu.com/p/98a141701cc7

免责声明:文章转载自《GitHub建立个人Maven仓库》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇精品 IDEA 插件大汇总!值得收藏HTTP Bearer认证及JWT的使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

【网络安全】window 快速搭建 ftp 及 多种访问方式

在局域网里面使用ftp传输文件比使用qq等软件传输速度快很多,但是搭建ftp很多时候需要下载相应的支持软件,其实不必下载相关的软件,因为window自带ftp功能。   演示操作系统:windows10   一、搭建 ftp  1.找到控制面板     2.打开控制面板 选择 程序   3.选择启用或关闭windows功能   4.选中 ftp 服...

Docker从入门到放弃

  为什么要学习 docker 呢?深有体会,由于一些原因只能在他人电脑上搭建环境,明明在自己电脑上的程序跑的好好的,在他人的电脑上就是死活出错。折磨人呀!!!!!可是能怎么办,工作还得继续,曲线救国呗,折腾了一天终于搞好了,那么以后呢?想到了之前搭建靶机时候用到的docker,时间长了也忘了,准备好好梳理学习入门一波。《十分感谢大神的文章,本文基于大神的...

FTP操作(FTPClient)

//FTP开源封装的类 using System; using System.Collections.Generic; using System.Net; using System.IO; namespace FTP {     /// <summary>     /// FTP客户端操作类     /// </summary>  ...

centos 卸载vsftpd方法

如果服务器上安装了vsftpd,配置出错需要卸载vsftpd 1、查询vsftpd [root@localhost ~]# rpm -aq vsftpd vsftpd-2.0.5-16.el5_5.1 #此处是查找vsftpd的返回结果 2、使用service vsftpd status 查看vsftpd的状态 service vsftpd status...

如何上传网站程序(文件浏览器上传网页、FileZilla上传网站程序)

问题场景: 网页制作完成后,程序需上传至虚拟主机。 注意事项: Windows系统的主机请将全部网页文件直接上传到FTP根目录,即/。 Linux系统的主机请将全部网页文件直接上传到/htdocs目录下。 由于Linux主机的文件名是区别大小写的,文件命名需要注意规范,建议使用小写字母,数字或者带下划线,不要使用汉字 。 如果网页文件较多,上传较慢,强烈建...

关于servu公网访问出现“打开ftp服务器上的文件夹时发生错误。请检查是否有权限访问该文件夹。详细信息:操作超时”的解决方法

最近给公司设置一个ftp服务器(当然是使用serv-u,:))在服务器设置好后,在本机可以访问,无论是使用ip地址(ftp://192.168.1.163),还是域名(例如域名:ftp://www.testftp.com),都正常,可是在公网上怎么访问都是出现“操作超时”的提示,上网也没有查到资料,后来看到一篇文章说是防火墙没有设置,我回过头来检查防火墙的...