前段時間自己寫了一個簡易的Java版爬蟲框架。如果想把這個框架完善還是需要大家的力量,如果每次使用都要從Gihub上下載源碼豈不是很麻煩?因爲自己的項目用的是maven來管理jar包,那麼就試試把這個爬蟲框架放到公服倉庫上去吧!
註冊Sonatype賬號
使用過Jira的用戶就很熟悉了,事務與項目跟蹤軟件。註冊好之後也可以用這個賬號登陸maven公服倉庫https://oss.sonatype.org/
注意:Username 一定不要是中文,一定要是英文!!!
創建一個Jira
Project: Open Source Project Repository Hosting (OSSRH)
Issue Type: New Project
下面是我項目的配置
注意Group Id 要和項目中pom配置的一樣,一定要是域名的反寫,這裏推薦使用github的域名(如果自己沒有長期維護的域名),自己的域名可能會過期github可是不能隨隨便便的過期吧~
Project URL 就是你項目再Github上的地址;
SCM url 就是項目clone地址
ok,創建好之後就等待老外回覆吧。因爲有時差,所以一般他們晚上十點鐘以後才能去審查,所以第一次配置的的時候一定要準確,不然改一次要等一天哦~~~
正確的審覈反饋如下:
修改項目Pom
這個也是比較重要的
一定要有以下結構
<description>A Simple Java Crawler Framework</description>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>wangxc</name>
<email>[email protected]</email>
</developer>
</developers>
<scm>
<connection>
scm:git:https://github.com/vector4wang/vw-crawler.git
</connection>
<developerConnection>
scm:git:https://github.com/vector4wang/vw-crawler.git
</developerConnection>
<url>https://github.com/vector4wang/vw-crawler</url>
</scm>
這是Nexus Rules規定的,不然會出錯!
然後就是構建插件與配置
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- java doc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
distributionManagement中對應MavenHome中的setting的文件配置,如下
<servers>
<server>
<id>ossrh</id>
<username>UserName</username>
<password>Password</password>
</server>
</servers>
用戶名和密碼就是你註冊sonatype時的用戶名和密碼,id要對應pom裏的id
nexus-staging-maven-plugin 這個插件是在成功發佈到公服上的時候不需要手動去改變status(close,有的文章介紹說要手動關閉)
maven-javadoc-plugin 這個也比較重要,生成javadoc,要求代碼裏如果要使用註釋,就要按照規範去註釋,這個大家可以查找相關內容瞭解下,你也可以在deploy的時候按照提示去修改代碼
maven-gpg-plugin 這個是用來生成私鑰,下面會用到
ps:我的電腦是mac,在打包的時候報錯,說找不到java home,在properti中加上下面配置就行了
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
安裝gpg
windows用戶在gpg4win這裏下載,mac可以下載GPG_suite
因爲都是圖形界面,所以直接創建新的祕鑰
需要輸入用戶名、郵箱和密碼,一定要記住這個密碼
之後需要把此祕鑰發佈到公鑰服務器上(因爲是圖形工具,很簡單,如果是命令行,還請在網上找一下)
發佈
一切配置好之後,可以使用mvn clean deploy
看一下結果,如果想發佈release版本的需要把version中的snapshot去掉即可~
發佈的時候提示你輸入密碼,這個密碼就是上一節中你輸入的密碼!
之後就可以在倉庫中找到自己發佈的jar包了,發佈release之後,要回到jira上接着評論告知已經發布,可以關閉掉這個jira了!!!
後記
最大的問題就是時差問題,因爲你遇到的問題可能需要老外那邊協助,比如重置一些權限或者其他稀奇古怪的問題,這樣一等就是一天。所以要準備十點以後,一旦jira有回覆,立馬去修改去嘗試,然後再告知老外,那是老外可能會立即做出迴應,就不需要等一天了~~~
另外後面會把爬蟲框架vw-crawler的使用說明補充出來,希望大家能多多捧場~~~
CSDN:http://blog.csdn.net/qqhjqs?viewmode=list
簡書:https://www.jianshu.com/u/223a1314e818
Github:https://github.com/vector4wang
Gitee:https://gitee.com/backwxc
如果感覺有幫助的話,點個贊哦~