Amazon

Wednesday, September 7, 2011

Leiningen, Maven and JDK7

A little while ago, I upgraded my machine at work to JDK7.  Everything seemed to be working fine until I needed to download a new artifact from our local Artifactory repository.  I kept getting messages that my connection was timing out.  After some investigation I figured out that JDK7 tries to use IPv6 by default and something on our local network didn't like that.  I found a System property, java.net.preferIPv4Stack that tells Java to try IPv4 first. I setup an environment variable

MAVEN_OPTS=-Djava.net.preferIPv4Stack=true
and everything seemed to work fine.

That is until yesterday when I tried to add a new dependency to a Leiningen project. Apparently, Leiningen doesn't utilize the MAVEN_OPTS variable. Instead, it uses

JAVA_OPTS=-Djava.net.preferIPv4Stack=true
Now everything is working again and life is good!.

2 comments:

  1. You can also put java opts in your Leiningen project.clj:

    :jvm-opts ["-Djava.net.preferIPv4Stack=true"]

    ReplyDelete
  2. That's interesting, thanks! But, how does that work? Isn't the jvm already running when project.clj is read?

    ReplyDelete