Expose your local Maven repository through http with Meecrowave
Sometimes it is convenient to expose its local maven repository through http. The most common case are to share with others some pre-downlaoded or pre-built artifacts on a poor or lack of internet connection. To be even more concrete: if you are teaching or doing some trainings you probably already understood what it is about.
There are several ways to do it but I would like to show that reusing Meecrowave server - Tomcat actually - it is already quite trivial. Since, for a Java developper, it is common to have such a server locally already, it can be a quick and efficient way to setup a maven server from your local repository.
To do it I'm using this web.xml which will work with all Tomcat based servers (Tomcat, TomEE, Meecrowave, ...):
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>readonly</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>jar</extension>
<mime-type>application/java-archive</mime-type>
</mime-mapping>
<mime-mapping>
<extension>war</extension>
<mime-type>application/java-archive</mime-type>
</mime-mapping>
<mime-mapping>
<extension>zip</extension>
<mime-type>application/zip</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pom</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
</web-app>
This just defines the default servlet, allows to list folder (it is easier to browse the repository this way) and prevent to upload files since we just want to expose our repository, not make it writable.
Finally grab Meecrowave runner jar and launch a server which deploys your maven repository as a webapp with this web.xml. Here what it looks generally, assuming you created a web.xml like the previous one in current directory:
java -jar meecrowave-core-1.1.0-runner.jar \
--webapp ~/.m2/repository \
--context maven2 \
--web-xml conf/web.xml \
--tomcat-default-setup false
It will deploy the server on the default port (8080) but you can customize it using --http option. The last option (tomcat-default-setup) avoids to setup the default servlet since we customized it in our web.xml. You can skip it if you want.
Now go on http://localhost:8080/maven2 and you should see your local maven repository.
Add it to a pom or settings.xml in your repositories list and you can grab artifacts from the computer which launched the server if it is on the same network.
Last tip: if you are using Ubuntu, you can easily create an Hotspot Wifi and then anyone connected to your Wifi could grab the artifacts you have in your local repository. No more need to ensure the conference/University has a great Wifi, no more need to pre-build a Docker or VirtualBox image, skipping part of the experience the students should get familiar with. To create such a Hotspot you can use this kind of command:
nmcli device wifi hotspot \
con-name MyConnection \
ssid MySSID band bg \
password MyPassword
From the same author:
In the same category: