Posted on 15-Jun-2019 16:14:13
If you working at a start-up or using a personal laptop/IaaS/PaaS account, you will have an advantage of admin privileges and no usage of a proxy or an artifact repository like Nexus. But if you are working for larger organisations, you will have trouble with admin privileges and a proxy that you need to setup. While browsers are automatically set to use the system proxy, unfortunately many tools (GUI or command line executables) do not pick them by default and will need you to explicitly set the proxy. In most of the cases it is a one-time setup that you need to do when you join the organisation or do a team movement. However, in the fast changing technology world and an ever increasing open source community, there are new tools/libraries/platforms/frameworks/services, etc that are coming up and you keep running into a need to download and try something new which may solve a problem for your team or simplify an existing solution.
In this post, I will cover the proxy and Nexus setup for few of the use cases.
– replace http with https if its a HTTPS based proxy.
– http_proxy is for HTTP connections and https is for HTTPS connections.
If your proxy requires a user name and password, provide those also.
You have 2 options for providing the proxy details and one way to set Nexus as a repository.
<id>proxyhost</id> <active>true</active> <protocol>http</protocol> <host>proxy.example.com</host> <port>proxyport</port> <username>username</username> <password>password</password> <nonProxyHosts>www.xyz.com</nonProxyHosts>
Set Nexus as your artifact repository in your settings.xml file to download the dependencies in your pom file.
<mirror> <id>central</id> <name>central</name> <url>http://your-host:8081/repository/maven-group/</url> <mirrorOf>*</mirrorOf> </mirror>
And to set the repository in your .pom file, add the below to it.
<repository> <id>maven-group</id> <url>http://your-host:8081/repository/maven-group/</url> </repository>
Proxy can be supplied for Maven or infact the java binary as well with the D options.
mvn -D java.net.useSystemProxies=true java -D java.net.useSystemProxies=true
mvn -Dhttp.proxyHost=[proxyhost] -Dhttp.proxyPort=[proxyport] -Dhttp.nonProxyHosts=[proxybypasshosts]
java D http.proxyHost=[proxyhost] D http.proxyPort=[proxyport] D http.nonProxyHosts=[proxybypasshosts]
You can use the proxy inside Java code by setting the System properties.
System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port);
Luckily pip, atleast on bash terminals uses the http_proxy and https_proxy environment variables. Put the following in your pip.conf file to use Nexus PyPI repository instead of the external pypi.org.
index = http://nexushost:8081/repository/pypi-all/pypi
index-url = http://nexushost:8081/repository/pypi-all/simple
On Mac, Docker Desktop can be located on the top panel. The proxy can be setup under Preferences->Proxies.
The proxy in STS can be setup under Preferences->General->Network Connections.