前言:mavn是比较常用的项目管理工具,如果在团队开发中,对于可公用的程序需要单独剥离出来并且仍想被maven管理的话,可能需要一个统一的远程jar管理平台,在maven系,有各种私服系统,我们在这里介绍一个轻量的maven代理器.其非常简单,对于小型公司,其足够实用..
maven-proxy是一个基于http/servert的服务器,用于存储基于maven的项目包(jar等)
maven-proxy的套路大概如下:
1)客户端开发机器,安装maven工具(http://maven.apache.org
)
2)远程代理端,安装maven-proxy(http://maven-proxy.codehaus.org
)
3)客户端maven通过配置远程jar代理服务器地址,来获取本地没有的jar
4)管理员或者开发者向proxy中push可用的maven项目(包括jar,source,pom.xml文件等)
5)开发机在maven项目中引用proxy中的jar
1.mavn-proxy的安装
从(http://maven-proxy.codehaus.org中下载maven-proxy,其有2个类型的安装程序
1)一个maven-proxy-standalone-0.2.zip:这个是基于java的一个程序,解压后获取jar.通过命令行执行其main方法以启动服务.
2)maven-proxy-webapp-0.2.zip:基于servet的java web项目,放在tomcat中既可使用..
maven-proxy应该是一个服务的方式被使用,我们在这里仅仅介绍,standaone方式的安装
maven-proxy在安装之前,需要对配置文件进行修改,这也是其服务得以正确使用的前提:
在其网站上下载*.properties文件(http://maven-proxy.codehaus.org/Configuration
)
如下是本人可用properties文件全文:
################ GLOBAL SETTINGS
# This is where maven-proxy stores files it has downloaded
repo.local.store=./target/repo
#The port to listen on - not used if loaded as a webapp
port=9999
#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour
#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using
#a prefix.
#The repository will be shown at http://localhost:9999/repository/
#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change)
# As maven doesn't like a trailing slash, this address shouldn't have one either.
prefix=repository
#This is the simple date format used to display the last modified date while browsing the repository.
lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss
################ SNAPSHOT HANDLING
#If you want the proxy to look for newer snapshots, set to true
snapshot.update=true
################ M2 METADATA HANDLING
#If you want the proxy to prevent looking for newer metadata, set to false (default is true)
#metadata.update=false
################ M2 POM HANDLING
#If you want the proxy to look for newer POMs, set to true (default is false)
pom.update=true
################ PROMOTION HANDLING
# ***** NOT CURRENTLY IMPLEMENTED *****
#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It
# is designed to be used by "higher security installations" that do not want to acquire artifacts from
# remote repositories without approval.
#
#If promotion handling is enabled, then the proxy will not download remote artifacts without permission
# (local repositories with copy=false are considered to be local)
#
#Permission to download is granted via the Promotion menu which will be enabled
# when promotion handling is enabled.
#
#If promotion is false, artifacts are sourced from any repository as per normal.
#
#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using
# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive.
##
promotion=false
################ WEB INTERFACE
# This defines the absolute URL the server should use to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
# The prefix will be added to this for the actual repository
# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository
serverName=http://localhost:9999
#If true, the repository can be browsed
browsable=true
#If true, the repository can be searched
searchable=true
#Not currently implemented. Will allow webdav access to the repository at some point.
webdav=true
#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only
#eg. /maven-proxy/style.css, http://www.example.com/style.css
stylesheet=/maven-proxy/style.css
#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme.
#If a stylesheet is set, these are not used.
bgColor=#14B
bgColorHighlight=#94B
#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme.
#If a stylesheet is set, these are not used.
rowColor=#CCF
rowColorHighlight=#DDF
################ PROXIES
#This is just a hack, it should auto discover them
proxy.list=one
#Unauthenticated proxy
proxy.one.host=repo.test.com
proxy.one.port=3128
#Authenticated proxy
#proxy.two.host=proxy2.example.org
#proxy.two.port=80
#proxy.two.username=username2
#proxy.two.password=password2
#Authenticated proxy
#proxy.three.host=proxy3.example.net
#proxy.three.port=3129
#proxy.three.username=username3
#proxy.three.password=password3
################# REPOSITORIES
#This is not just a hack, it specifies the order repositories should be checked
#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/"
repo.list=repo-test-com
#local-store
# The local store represents a location that local jars you host can be located.
# This could also be achieved by having a local http repository, but this is less cumbersome
repo.local-repo.url=file:///./target/repo-local
repo.local-repo.description=Super Secret Custom Repository
#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos
repo.local-repo.copy=false
#If hardfail is true, any unexpected errors from the repository will cause
#the client download to fail (typically with a 500 error)
repo.local-repo.hardfail=true
#Don't cache a file repository
repo.local-repo.cache.period=0
repo.repo-test-com.url=http://repo.test.com/repository
repo.repo-test-com.description=maven2
repo.repo-test-com.url.proxy=one
repo.repo-test-com.url.cache.period=3600
repo.repo-test-com.hardfail=false
repo.repo-test-com.cache.failures=true
配置文件中,url信息均是描述性信息,没有任何实际意义,这些信息会在你启动服务后,在页面上得以展示.
A)在系统中创建需要放置服务程序的路径:/usr/local/mvn-proxy
B)把maven-proxy-standalone-0.2-app.jar放在目录中,同时也把修改后的mavn-proxy.properties文件放在同一目录
C)在目录中,创建放置库文件的目录/target/repo(此文件夹名和properties中的配置信息保持一致)
D)新建一个命令文件:startup.sh
#!/bin/bash
java -jar maven-proxy-standalone-0.2-app.jar maven-proxy.properties
同时给sh文件权限:chmod u+x startup.sh
到目前位置,mavn-proxy准备工作基本结束.只需实行startup.sh既可启动服务
服务的默认配置端口是9999,如果你的系统有防火墙(linux),请赦免9999端口访问..
此时你在浏览器中输入:http://你的服务器ip:9999/
既可看到maven-proxy服务的首页,通过点击repository,可以查看库的信息.
2.maven的配置
proxy已经可用,那么如何通过maven(客户端)来获取或者感知proxy中的依赖包呢??
灰常简单....一贯作风,编辑maven的setting.xml增加其proxy配置信息既可,找到profiles标签
在其尾部增加如下信息:
<profile>
<id>central-repo</id>
<repositories>
<repository>
<id>local-repo</id>
<name>Internal Repository</name>
<url>http://192.168.0.105:9999/repository</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local-repo</id>
<name>Internal Repository</name>
<url>http://192.168.0.105:9999/repository</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
注意请讲url修改为自己的proxy服务器地址.其他信息可以不变...
当配置完profile后,请你别忘去激活它,激活的方式有2中,一个是在项目的pom.xml配置引用激活,另一种方式就是全局激活,全局激活需要修改maven的setting.xml文件.在文件中增加
<activeProfiles>
<activeProfile>central-repo</activeProfile>
</activeProfiles>
activeProfile的值要和你配置的profile的id保持一致.
3.发布jar
上面我们曾经建立过一个文件路径:mven-proxy/target/repo
发布jar,需要手动在此目录中增加文件,比如我要发布一个message-client-1.1.0.jar
规范的目录结构应该是:mven-proxy/target/repo/com/test/message-client/1.1.0
然后把你的message-client-1.1.0.jar,message-client-1.1.0.pom,_maven.repositories三个问题全部放在目录中..
启动服务后,你就在页面上看到相应的jar...
程序对proxy中jar的引用和普通jar依赖一样,无须做更多的配置...
分享到:
相关推荐
maven-proxy-parent :在单个 pom 中包含依赖项管理和应用程序启动配置。 maven-proxy-server :包含maven-proxy-server的编程逻辑,但未提供工件存储的详细信息。 maven-proxy-oauth2 :启用 api,以便用户可以...
maven-proxy-webapp-0.1.jar
maven-proxy-core-0.2.jar
maven-proxy-core-0.1.jar
小Maven代理 确切地说,它是Maven的微型代理服务器,您可以在本地网络上运行。 目前唯一要做的是Maven下载并缓存代理内容。 如果您的互联网连接速度较慢,并且有多台计算机或一个团队正在构建和下载文件,那么这是...
maven-proxy-standalone-0.2-app.jar
maven-proxy-standalone-0.1-uber.jar
本文将深入探讨“新建Maven项目失败”问题以及如何使用`maven-archetype-quickstart-1.1.jar`解决这个问题。 首先,当我们尝试使用Maven创建一个新项目时,通常会使用`mvn archetype:generate`命令,这个命令基于一...
Bazel Maven代理 Bazel的本地(只读)代理,可访问安全存储库后面或本地Maven存储库中的Maven资源 产品特点 提供对需要通过https://127.0.0.1:8499/maven/<repository>/...进行身份验证的Maven存储库的无密码访问...
赠送Maven依赖信息文件:netty-handler-proxy-4.1.73.Final.pom; 包含翻译后的API文档:netty-handler-proxy-4.1.73.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-handler-proxy:4.1.73....
赠送Maven依赖信息文件:netty-handler-proxy-4.1.73.Final.pom; 包含翻译后的API文档:netty-handler-proxy-4.1.73.Final-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.netty:netty-handler-proxy...
赠送Maven依赖信息文件:hadoop-yarn-server-web-proxy-2.6.0.pom; 包含翻译后的API文档:hadoop-yarn-server-web-proxy-2.6.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.hadoop:hadoop-yarn-...
赠送Maven依赖信息文件:netty-handler-proxy-4.1.68.Final.pom; 包含翻译后的API文档:netty-handler-proxy-4.1.68.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-handler-proxy:4.1.68....
【标题】"maven配置proxy和archetype"涉及的是在使用Maven构建Java项目时,如何设置代理服务器(proxy)和创建项目模板(archetype)的相关知识。在开发环境中,尤其是公司网络通常需要通过代理服务器访问外部资源,...
赠送Maven依赖信息文件:netty-handler-proxy-4.1.74.Final.pom; 包含翻译后的API文档:netty-handler-proxy-4.1.74.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-handler-proxy:4.1.74....
赠送Maven依赖信息文件:netty-handler-proxy-4.1.74.Final.pom; 包含翻译后的API文档:netty-handler-proxy-4.1.74.Final-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.netty:netty-handler-proxy...
Bodgeit-Maven 这是一个从zap-maven-plugin 1.2和ZAproxy 2.4.2开始的示例项目。 这是一个具有Selenium测试的示例Web应用程序,该测试在Maven的测试阶段执行。 它重复使用相同的Selenium测试来为zap-proxy应用程序...
4. **项目对象模型**(POM):POM是Maven的核心,它定义了项目的元数据,包括项目依赖、构建配置、插件配置等,使得项目配置具有高度的可重用性和一致性。 5. **标准目录结构**:Maven 建议所有项目采用统一的目录...
总结来说,"smileys-proxy-servlet"是一个使用Java和Smiley库构建的HTTP代理服务实现,它结合了IDEA和Maven的便利性,适用于需要搭建HTTP代理服务的场景。如果你想要深入了解或定制HTTP代理行为,这个项目和库是一个...
`zap-maven-plugin`是针对Maven构建系统的插件,使得开发人员能够方便地在构建过程中集成ZAP自动化安全测试。 **ZAP插件的安装与配置** 在Maven项目中使用`zap-maven-plugin`,首先需要在`pom.xml`文件的`<build>`...