Maven Proxy Details


Update: I included an extra proxy configuration in my example below that would normally be unecessary. I included it so that I would still be able to run builds and update my local repository when our instance of Maven Proxy was down. I also used it to access the Mojo sandbox on codehau.org so that I could finally figure out how to compile Groovy under Maven. In most cases including the extra proxy settings is akin to placing your coffee maker on a lit gas stove to keep the carafe warm. What I’m trying to say is you would most likely not need to do it unless your the type that particularly appreciates the idea of dispoable Mr. Coffee makers.

I must admit that I got lucky when I finally made Maven Proxy work for me. Ok, it might not have been luck, rather it was a stroke of persistance. I had people telling me on the mailing lists that it would not work, they couldn’t get it to work, and it it was not compatible with Maven 2. The web site had next to no documentation and at this point I don’t even rememeber how I got so lucky, ahen… persistent. Long story short, the majority of my problem (and the problem I attempted to address here) was related to our in office HTTP proxy. That dang thing has been the core of more problems than I care to think about.

So What?
Why am I wasting your time explaining how hard Maven proxy was for me to setup? I have a reader who is trying to get Maven Proxy working and that reader may not be as lucky… err persistant,,, as I was or am. My last posting about Maven Proxy left out some details and that’s no good. So, with the hope of loading my site chock full of useful information for people like myself who struggle on a daily basis, and also in an attempt to be a nice guy and go out of my way, I will present to you, my loyal reader, the rest of the details regarding Maven Proxy configuration.

Setting Up the Maven Proxy Config File
For the most part you can use the default settings in the Maven Proxy config file. I use something similar to the following (names changed to protect the guilty!):


################ GLOBAL SETTINGS
# This is where maven-proxy stores files it has downloaded
repo.local.store=./maven/repo-cache

#The port to listen on - not used if loaded as a webapp
port=8080

#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=mvnrepo

#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:8080

#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=instagate

#Authenticated proxy
proxy.instagate.host=instagate.mycompany.com
proxy.instagate.port=8080
proxy.instagate.username=ccc
proxy.instagate.password=mypassword

################# 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=local-repo,www-ibiblio-org,dist-codehaus-org

#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:///./maven/repo-local
repo.local-repo.description=In-office Maven 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


#www.ibiblio.org
repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2
repo.www-ibiblio-org.description=www.ibiblio.org
repo.www-ibiblio-org.proxy=instagate
repo.www-ibiblio-org.hardfail=false
#Cache this repository for 1 hour
repo.www-ibiblio-org.cache.period=3600
repo.www-ibiblio-org.cache.failures=true

#dist.codehaus.org
repo.dist-codehaus-org.url=http://dist.codehaus.org
repo.dist-codehaus-org.proxy=instagate
repo.dist-codehaus-org.hardfail=false
repo.dist-codehaus-org.cache.period=3600
repo.dist-codehaus-org.cache.failures=true


The important part is the local cache setting along with the prefix. The prefix controlls the URL that the proxy will respond to while the local cache setting controls where the proxy will write it’s cached artifacts that it gets from the internet. You’ll want to point the local cache property to a folder that has adequate space for a potentially large repository. You’ll note that I use relative paths for the cache setting. My paths are relative to the working folder of my servlet container’s process. If you get confused where your paths are relative from then use absolute paths. The other important setting you need to consider is the properties file location setting in the web.xml for Maven Proxy. I expanded my copy of Maven Proxy and edited the web.xml adding the following before repackaging everything up for deployment.

    <context-param>
        <param-name>maven-proxy.properties</param-name>
        <param-value>/home/newaredev/webservers/jetty-5.1.5rc1/maven/conf/repo-proxy.properties</param-value>
        <description>Controls where maven-proxy grabs its properties from</description>
    </context-param>

Lastly you ned to edit your settings.xml file that lives under the $HOME/.m2/ folder. My copy looks similar to this:


<settings>
	<proxies>
		<proxy>
			<active>true</active>
			<protocol>http</protocol>
			<host>instagate.mycompany.com</host>
			<port>8080</port>
			<username>ccc</username>
			<password>mypassword</password>
		</proxy>
	</proxies>
	<mirrors>
		<mirror>
			<mirrorOf>central</mirrorOf>
			<id>myproject-repository-repohost</id>
			<name>repohost Repo</name>
			<url>http://repohost.mycompany.com:8080/mvnrepo/repository/</url>
		</mirror>
	</mirrors>
	<profiles>
		<profile>
			<id>default-profile</id>
			<activation>
				<activeByDefault>TRUE</activeByDefault>
			</activation>
			<repositories>
				<repository>
					<id>myproject-repository-repohost</id>
					<name>repohost Repo</name>
					<url>http://repohost.mycompany.com:8080/mvnrepo/repository/</url>
					<snapshots>
						<enabled>TRUE</enabled>
					</snapshots>
					<releases>
						<enabled>TRUE</enabled>
					</releases>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>myproject-repository-repohost</id>
					<name>repohost Repo</name>
					<url>http://repohost.mycompany.com:8080/mvnrepo/repository/</url>
					<snapshots>
						<enabled>TRUE</enabled>
					</snapshots>
					<releases>
						<enabled>TRUE</enabled>
					</releases>
				</pluginRepository>
			</pluginRepositories>
		</profile>
		<profile>
			<id>Snapshots</id>
			<repositories>
				<repository>
					<id>Maven Snapshots</id>
					<url>http://snapshots.maven.codehaus.org/maven2/</url>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
					<releases>
						<enabled>false</enabled>
					</releases>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>Maven Snapshots</id>
					<url>http://snapshots.maven.codehaus.org/maven2/</url>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
					<releases>
						<enabled>false</enabled>
					</releases>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
</settings>


One more word of advice would be to watch out under windows. When my buddy installed Maven 2 on XP somehow one of the default or example settings.xml files got considered before the one in his home folder. I cost us hours to figure out but afterwards we renamed all other occurences of the settings.xml file in the distribution and got around the problem. I would be a little more descriptive but it’s getting late in the day and honestly many of the details escape me. I believe everything I listed here should be sufficient enough for most people to get started. I have heard word of some alrenative solutions but I cannot remember the names. When I get time I’ll do the research and possibly set them up instead of our current proxy. Until then, hit me up…

15 thoughts on “Maven Proxy Details

  1. Hi, you can explain more details where put your directories, for example in windows xp.
    I dont know what i am doing wrong,

    the property: repo.local.store=./maven/repo-cache. Is a directory in c:\maven\repo-cache or is in the maven-proxy webapp?

    prefix=mvnrepo
    this prefix in the settings.xml why is: http://repohost.mycompany.com:8080/mvnrepo/repository/, it would have to be:
    http://repohost.mycompany.com:8080/mvnrepo/ ???

    thanks! a lot
    Juan Carlos

  2. I’ll answer quickly and stoopidly because I’m supposed to be earning some pull-ups for my two year old and generating revenue to power the light that my 7 year old reads by. (Sorry if my answer isn’t thoruough enough. Just comment and I’ll holla back.) The repo.local.store points relative to the JVM working folder, though I think I mentioned earlier that you can use an absolute path if you don’t know what the working folder is or will be. I used a relative path because I’m starting the proxy from a Jetty instance on the command line like an idiot. (Ideally it would be a system service, so using relative paths probably isn’t ideal.) The prefix property I’m not too sure of. If I’m not mistaken it controls the context path that the all-in-one distribution binds the webapp to or something like that. (I think it’s actually ignored when you use the WAR distribution.) I happen to have the war file named the same as the prefix (I snuck that detail in without telling you because I wanted you to be confused!) so by J2EE convention that’s where the proxy web-app is bound to. The “repository” string is a hard coded path that the servlet within the web-app responds to and does not appear to be configurable. So in short the path you should use in settings.xml is “http://[repohost].[domain]:[port]/[webapp-name]/repository”

  3. Hi there,

    I’m having problems getting maven-proxy (MP) to work. There is one thing I don’t understand. I’m in a corporate network and internet access is provided by a proxy (P). Only I have access to internet and I can’t share username/password to Internet for security reasons. That’s why I want to use MP to provide access to dependencies outside our local repository. That being said, I don’t understand why we have to declare P twice (with username and passsword).

    – in MP conf file. Which I think is normal.
    – in settings.xml. Which I think is not because everyone would be able to see username/password

    If we do need to declare P in settings.xml, then what’s the point in using MP? Aggregating repositories could very well be done in a parent POM or within settings.xml !

    I feel we missed something…

  4. Hi again,

    Eventually !!! I managed to get maven proxy to work as I intended.

    In settings.xml, don’t specify anything for proxies but instead define the maven-proxy url as a mirror of central and that would be it. I recommend doing those modifications at installation level, editing “%M2_HOME%/conf/settings.xml”

    you can find below my conf files:

    maven proxy config file


    ################ GLOBAL SETTINGS
    # This is where maven-proxy stores files it has downloaded
    repo.local.store=target/repository

    #The port to listen on - not used if loaded as a webapp
    port=62836
    #port 62836 because in SMS it means maven :)

    serverName=http://:62836

    {...}

    ################ PROXIES
    #This is just a hack, it should auto discover them
    proxy.list=one

    #Authenticated proxy
    proxy.one.host=
    proxy.one.port=
    proxy.one.username=
    proxy.one.password=

    ################# 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=local-repo,repo1-maven-org

    #local-store
    repo.local-repo.url=file:///V:\mvn_rep
    repo.local-repo.description=Custom Repository
    repo.local-repo.copy=false
    repo.local-repo.hardfail=true
    repo.local-repo.cache.period=0

    #repo1.maven.org
    repo.repo1-maven-org.url=http://repo1.maven.org/maven2
    repo.repo1-maven-org.description=repo1.maven.org
    repo.repo1-maven-org.proxy=one
    repo.repo1-maven-org.hardfail=true
    repo.repo1-maven-org.cache.period=3600
    repo.repo1-maven-org.cache.failures=true
    repo.repo1-maven-org.copy=true

    %M2_HOME%/conf/settings.xml

  5. Hi again,

    Eventually !!! I managed to get maven proxy to work as I intended.

    In settings.xml, don’t specify anything for proxies but instead define the maven-proxy url as a mirror of central and that would be it. I recommend doing those modifications at installation level, editing “%M2_HOME%/conf/settings.xml”

    you can find below my conf files:

    maven proxy config file

    repo.local.store=target/repository

    #The port to listen on - not used if loaded as a webapp
    port=62836
    #port 62836 because in SMS it means maven :)

    serverName=http://:62836

    {...}

    ################ PROXIES
    #This is just a hack, it should auto discover them
    proxy.list=one

    #Authenticated proxy
    proxy.one.host=
    proxy.one.port=
    proxy.one.username=
    proxy.one.password=

    ################# 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=local-repo,repo1-maven-org

    #local-store
    repo.local-repo.url=file:///V:\mvn_rep
    repo.local-repo.description=Custom Repository
    repo.local-repo.copy=false
    repo.local-repo.hardfail=true
    repo.local-repo.cache.period=0

    #repo1.maven.org
    repo.repo1-maven-org.url=http://repo1.maven.org/maven2
    repo.repo1-maven-org.description=repo1.maven.org
    repo.repo1-maven-org.proxy=one
    repo.repo1-maven-org.hardfail=true
    repo.repo1-maven-org.cache.period=3600
    repo.repo1-maven-org.cache.failures=true
    repo.repo1-maven-org.copy=true

    %M2_HOME%/conf/settings.xml

    {...}

    D:\projects\.m2\repository

    mirrorId
    central
    Redirection to the maven-proxy repository address.
    http://algol.stars.fr:62836/repository

    {...}

    That’s it !!

  6. The good news is you don’t need the proxy credentials in two places. I had mine in both places to to confuse readers and to compensate for an occasion where our maven-proxy server was banned from the internet. (I still needed to run my build and update my local repo.) Generally, if you have maven proxy up and running then you don’t need proxy credentials in your settings.xml. More simply put, the proxy section in settings.xml is used for direct access to the internet from maven. When you talk to an instance of Maven-Proxy on you’re local network you don’t talk through a proxy so that section can be omitted. In your scenario all of the workstations that talk to Maven-Proxy can omit the proxy section in settings.xml. Now let me confuse you a little. In a more awkward environment where there is a proxy between you and your instance of Maven-Proxy you would need the proxy credentials section. My apologies for the mis-understanding.

  7. Yes, you are right on track. Like I posted above, the extra proxy settings are unecessary. Often on medium such as my blog you’ll find the blind teaching the deaf. I wrote the post with a basic understanding of it myself. There are a few things that I left out and readers have corrected me. I’ll post an update above to avoid confusing people further.

  8. Here’s the missing part:

    %M2_HOME%/conf/settings.xml

    {...}

    D:\projects\.m2\repository

    mirrorId
    central
    Redirection to the maven-proxy repository address.
    http://algol.stars.fr:62836/repository

    {...}

  9. sorry for the unreadable xml I included but I don’t know how to make tags appear correctly…. anyway, you guys got it right, right?? 🙂

    enjoy maven

  10. Hi there,
    I am looking for an answer of this question “what it means by the …cache.period=3600?”
    Actually i want to know whether the cache is cleared after a definite time.

  11. Modhu,

    I haven’t touched MAven Proxy in some time now. I’ve moved on to Artifactory which has a brilliant UI. I’d say your guess at the cache.period is a good one but I can’t confirm. If you’re having troubles though, I reccommend switching to something like Archiva or Artifactory or Proximity. Either one of these tools will likely be simpler to setup.

  12. Hi..

    I need solution and it is very urgent to me.
    I have configured my eclipse with maven-jetty plugin.
    It is working fine. The console part is also showing the jetty server is running. i am able to open http://localhost:8080/.
    But my problem is that when i am trying to use some url like this
    “http://localhost:8080/gadgets/ifr?url=http://blog.outer-court.com/homepage/miniweb.xml”

    It is showing HTTP 500 error.
    I think my shindig server is not able to render the gadget
    to my explorer. Please suggest me..

    karunjay Anand.

  13. I’m not quite certain where your issue is exactly but I’d start looking at the obvious. With jetty, hitting localhost:8080 should give you a link to all of your installed/deployed webapps. Find your webapp in this list and click its link. You can double check the spelling this way. (gadgets vs. gadget etc.) Next double check your web.xml to ensure your servlet/jsp is bound to the correct context path. Judging from your example you have either a JSP or a servlet you are trying to bind to the ifr context path from your gadgets webapp. Finally if there’s a 50 error you may get some log output from the console where you run mvn-jetty. (I’m not familiar with the plugin but you can run the cmd from the command line the same way and get log output to the console.) Look at your stack traces if any and try to resolve the issue from there.

Leave a comment