maven本地仓库nexus
nexus的安装
下载nexus
在nexus官网可以下载最新的nexus私服,现在通过官网可以直接下载bundle方式,他提供一个整合的包,直接运行就能启动nexus环境。
安装
下载后解压到本地tar -zxvf
即可。 解压后设置配置文件nexus-2.2-01/conf/nexus.properties
,可以修改监控ip和相应的端口。修改完成后进入bin/
目录,通过./nexus start
即可以启动nexus。 使用./nexus stop
可以停止nexus服务。
配置nexus私服
登陆nexus
用本地链接加上相应端口: http://localhost:8081/nexus/, 默认用户名密码为admin/admin123。
修改可以下载Repair index
第一步修改仓库的默认下载索引为true, 点击Views/Repositories —> Repositories,找到右边的Apache Snapshots,Codehaus Snapshots和Central,把标签下面的Configuration下把Download Remote Indexes修改为true。然后将这三个工程右键选择Repair index。
建立自己的私有库
Repositories –> Add –> Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,比如分别填入myrepo和 my repository,另外把Deployment Policy设置为Allow Redeploy,点击save就创建完成了
修改nexus仓库组
Nexus中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。
neuxs-2.2中默认自带了一个名为“Public Repositories”组,点击该组可以对他保护的仓库进行调整,把刚才建立的公司内部仓库加入其中,这样就不需要再在maven中明确指定内部仓库的地址了。同时创建一个Group ID为public-snapshots、Group Name为Public Snapshots Repositories的组,把Apache Snapshots、Codehaus Snapshots和Snapshots加入其中。
修改maven的setting.xml配置文件
maven安装好默认是没有配置仓库信息,此时mavne都默认去远程的中心仓库下载所依赖的构件。既然使用了私服,就需要明确告诉maven去哪里下载构件,可以在三个地方进行配置,分别是是mavne的安装目录下的conf下的settings.xml文件,这个全局配置,再一个是在userprofile/.m2目录下的settings.xml,如果不存在该文件,可以复制conf下settings.xml,这个是针对当前用户的,还有一个是在pom.xml中指定,其只对该项目有效,三个文件的优先级是pom.xml大于.m2,.m2大于conf下。
settings.xml的配置如下:
在profiles段增加一个profile
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<name>local private nexus</name>
<url>http://192.168.1.68:8081/nexus/content/groups/public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
另外,仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储的大部分构件类型。另外一种构件类型是插件。如果不配置pluginRepositories,那么执行maven动作时,还是会看到去远程中心库下载需要的插件构件,所以这里一定要加上这个。
在settings.xml中指使配置了profile还不行,需要激活它,在activeProfiles段,增加如下配置:
<activeProfile>nexus</activeProfile>
添加pom从本地仓库下载
<repositories>
<repository>
<id>nexus-public</id>
<name>nexus publiu</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<name>nexus snapshots</name>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-pulign</id>
<name>nexus pluign</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<name>neuxs snapshots</name>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
添加第三方jar包依赖
有些自己导入的类需要导入到本地仓库的,可以在nexus中将pom文件和jar包导入第三方库即可。
具体方法:View/Repositories -> Repositories -> 3rd party -> artifact upload -> GAV Definition 选择 From POM (此时既是通过pom导入相关类) -> Select Artifact(s) for Upload -> 导入相应的jar 包和pom文件即可。
添加第三方其他库文件
有些工程需要依赖第三方库文件。 可以在nexus中导入proxy工程的方式,就可以增加新的依赖库。
使用命令行建立Maven工程
使用命令行建立Maven工程的方法:
mvn archetype:generate -DgroupId=com.pengjunjie -DartifactId=idTest -DpackageName=nameTest -Dversion=1.0
archetype:create create是个被废弃或不被推荐使用的插件,在以后创建项目中请尽量使用archetype:generate
创建一个项目,如下:
mvn archetype:generate -DgroupId=com.demo.mvn -DartifactId=mvnDemo -DpackageName=mvnDemo -Dversion=1.0
进入要创建的目录
创建web工程:
mvn archetype:create -DgroupId=com.demo.mvn -DartifactId=mvnDemo -DarchetypeArtifactId=maven-archetype-webapp
创建java工程:
mvn archetype:create -DgroupId=com.demo.mvn -DartifactId=app
建好后,进入工程目录,
eclipse下编译:
mvn eclipse:clean eclipse:eclipse
myeclipse下编译:
mvn eclipse:myeclipse -Dwtpversion=2.0
mac下安装maven环境
mac下maven的安装
1. 下载maven组件包
访问maven官方下载链接,下载apache-maven-3.2.3-bin.tar.gz linux软件版本包。
2. 安装maven组件
将apache-maven-3.2.3-bin.tar.gz 解压到需要的文件夹
mv apache-maven-3.2.3-bin.tar /Users/valentine/workspace/tools/
tar -zxvf apache-maven-3.2.3-bin.tar
修改首启动文件,让环境变量启动时加载
vi ~/.bash_profile
MAVEN_HOME=/Users/valentine/workspace/tools/apache-maven-3.2.3
PATH=$PATH:$MAVEN_HOME/bin
export MAVEN_HOME
export PATH
将上述设置好之后注销当前用户,重新登录后生效。
执行mvn -version
之后可以测试是否安装成功
3. 配置setting.conf文件
修改setting.conf文件之后在eclipse中加入即可。
maven一些使用说明
maven有时候同步失败的话,重启一下eclipse然后再重新下载,可以继续同步中央仓库,不然一直开着是不能同步的。
有时候同步不了的时候将repo文件夹中的文件删掉之后会重新进行同步。
mac下安装mysql
mac下安装mysql主程序
访问mysql官方下载页, 选择社区版本 MySQL Community Edition , 在MySQL Community Downloads 界面下载MySQL Community Server 。 进入之后会根据服务器选择相应的mysql版本,在Mac OS上的MySQL的版本很多,选择64位10.8版本的,然后就是文件的后缀名有.tar.gz的和.dmg的,这里我选择的是.dmg的。点击右侧的download进行下载。
安装mysql-5.5.16-osx10.6-x86_64.pkg 主程序包。
安装workbench
下载mac workbench安装包,用同样的方法安装到mac上即可。
workbench提供MySQL设计器,以及MySQL相关的方便的可视化操作方法。
MySQL服务在mac下得操作方法
启动MySQL服务sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
停止MySQL服务sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
重启MySQL服务sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
管理数据库的访问密码
MySQL的默认账号密码是root/root,正常情况下我们如果单纯的只是使用MySQL Workbench来管理数据库的这个账号是可以的,但是当我们在编程代码中通过jdbc来访问MySQL时我们就会发现使用这个账号是不行,无法访问,因为MySQL需要我们更改密码,也就是说root这个是个默认的密码也就是弱密码,需要我们修改之后才能在代码中使用。因此我们需要来管理数据库的访问密码。
新建一个Server Instance
在“Server Administration”模块下有个“New Server Instance”点击之后会弹出一个“Create New Server Instance Profile”的对话框,跟着对话框的一步一步走就可以完成,一般本地的数据库直接跟着默认设置就ok。完成之后我们就能够在Workbench的主界面最右边看到刚才建立的instance。
使用命令登陆MySQL
使用workbench可以用命令行操作,但是怎么用都觉得不太习惯,还是命令行的方式来的比较快。整合了一下相应的mac下命令行使用方法。
在mac下安装之后,需要转换相关命令行
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
给root创建密码:
/usr/local/mysql/bin/mysqladmin -u root password root
使用终端来打开或关闭mysql:
sudo /Library/StartupItems/MySQLCOM/MYSQLCOM [start | stop | restart]
进入数据库:
mysql -u root -p
随后输入密码:root
将命令输入到启动项中得方法:
在终端输入 :
cd ~
vim ./bash_profile
这个文件如果配置过android开发环境是修改过的.我们添加2行
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
保存退出,重启终端或者开新窗口即可
到这里可以参考一下基本命令行操作:
Copyright © 2020 鄂ICP备16010598号-1