前言
个人笔记,以及想要记录git和maven的使用
Git
一、安装
- apt install git
- git version
二、登陆github注册账号
三、配置
- 建议少用root用户进行操作,多使用普通用户,避免项目权限不足
- git config --global user.name “用户名”
- git config --global user.email “github的邮箱”
- ssh-keygen -t rsa -C “github的邮箱”
四、使用
- https://github.com/settings/keys
- 点击【New SSH key】
- 将(服务器/虚拟机)生成的公钥【~/.ssh/id_rsa.pub】文件内容复制到GitHub网站的设置sshkey
- 在(服务器/虚拟机)输入命令测试,【ssh -T git@github.com】
- 不成功,一般为ssh有问题,或者GitHub设置sshkey失败;还有ssh为当前用户,假设用root和普通用户,请确认对象的.ssh
maven
一、安装
- apt install maven
- mvn -v
二、配置
- cd /usr/share/maven/conf
- vim setting.xml
- 修改来源
# 1,本人使用root用户(打脸,后面遇到恶心的权限问题,记录一下),其他用户请修改对应名称,尽量不使用root用户,防止权限问题
<localRepository>/root/.m2/repository</localRepository>
# 2,修改为阿里云
<mirror>
<id>nexus_aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
三、使用
- 打包
# 单纯打包,不导出其他依赖jar,导出给其他本地项目使用这个工具jar
mvn clean install dependency:copy-dependencies -DincludeScope=runtime -Dmaven.test.skip=true
# 打包,需要发布项目,依赖导入当前项目的lib文件夹
mvn clean install dependency:copy-dependencies -DoutputDirectory=lib -DincludeScope=runtime -Dmaven.test.skip=true
- 将本地打包的jar放到本地仓库,提供其他项目使用,只需要将打包好的jar转到本地仓库
mvn install:install-file -Dfile=打包的jar文件路径 -DgroupId=项目id -DartifactId=项目文件 -Dversion=版本 -Dpackaging=包类型
mvn install:install-file -Dfile=./target/core-1.0.0.jar -DgroupId=com.mozhitong -DartifactId=core -Dversion=1.0.0 -Dpackaging=jar
- 其他项目使用,与其他导入依赖方式一致
<dependency>
<groupId>com.mozhitong</groupId>
<artifactId>core</artifactId>
<version>1.0.0</version>
</dependency>
- 不想要打包发送的本地仓库,可以使用直接导入jar,但是不利于发布,只能方便开发和测试
<dependency>
<groupId>com.mozhitong</groupId>
<artifactId>core</artifactId>
<version>1.0.0</version>
<scope>system</scope>
# jar的路径
<systemPath>${project.basedir}/lib/core-1.0.0.jar</systemPath>
</dependency>
四、记录(忽略)
- 关闭项目,对于已经启动的项目,进行关闭
#!/bin/bash
# 默认最多有一个进程匹配到
echo `ps -ef|grep 'java' |grep 'xxx.jar'`
# 获取进程pid
pid=`ps -ef | grep 'java' | grep 'xxx.jar' | awk '{print $2}'`
if [ ! $pid ];then
echo "PID is null"
else {
echo "PID is "$pid
`kill -9 $pid`
echo "kill -9 "$pid
}
fi
- 底层复用项目,打包jar,发布到本地仓库,或者私有仓库
#!/bin/bash
# git pull 更新代码
git pull
# 启动log重置
> cat.log
# remove file 将无用的旧文件删除
rm -rf target/ || true
# mvn package 打包
mvn clean install dependency:copy-dependencies -DincludeScope=runtime -Dmaven.test.skip=true >>cat.log
# 找到pom.xml里面的版本号
version=`awk '/<version>[^<]+<\/version>/{gsub(/<version>|<\/version>/,"",$1);print $1;exit;}' pom.xml`
if [ ! $version ];then
echo "version isnull"
else {
# mvn 发送本地仓库,提供使用
mvn install:install-file -Dfile=./target/core-${version}.jar -DgroupId=com.mozhitong -DartifactId=core -Dversion=${version} -Dpackaging=jar >>cat.log
# 放到私有仓库,给朋友和自己使用
cp -rf ~/.m2/repository/com/mozhitong/core/* ~/repository/com/mozhitong/core/
}
fi
- 发布项目打包,启动
#!/bin/bash
# git pull 更新代码
git pull
# 启动log重置
> cat.log
# remove file 将无用的旧文件删除
rm -rf target/ lib/ config/ context/ xxx.jar || true
# mvn package 打包
mvn clean install dependency:copy-dependencies -DoutputDirectory=lib -DincludeScope=runtime -Dmaven.test.skip=true
# mv file 将打包好的文件移动到执行的目录下
mv target/classes/config/ config/
mv target/xxx.jar .
mv target/classes/context/ context/
# stop 停止
pid=`ps -ef|grep 'java' |grep 'xxx.jar' |awk '{print $2}'`
if [ $pid ];then
`kill -9 $pid`
fi
# start 启动
nohup java -Xms30m -Xmx128m -jar xxx.jar > cat.log 2>&1 &