Java update broke my Maven

I like new stuff. So today I launched Software Update and discovered a Java update! I squealed with excitement about having the shiniest new JVM on the block.

Then I went to build something with Maven:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
Caused by: java.lang.ClassNotFoundException:     org.codehaus.plexus.classworlds.launcher.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

And the paths were all screwy:

[steve-imac:/usr/local/m2]$ which mvn
/usr/bin/mvn

Thats not right. That isn’t my Maven install dir, the correct one is /usr/local/apache-maven-2.2.1/

Digging further:

[steve-imac:/usr/bin]$ ls -la | grep mvn
lrwxr-xr-x 1 root wheel 24 9 Mar 14:43 mvn -> /usr/share/maven/bin/mvn
[steve-imac:/usr/bin]$ cd /usr/share/
[steve-imac:/usr/share]$ ls -la maven
lrwxr-xr-x 1 root wheel 16 9 Mar 14:43 maven -> java/maven-3.0.2

It seems Apple has snuck Maven 3 in with this Java update!

Simple fix:

sudo rm /usr/bin/mvn
sudo ln -s /usr/local/apache-maven-2.2.1/bin/mvn /usr/bin/mvn

Maven restored.

Kudos to Chris who got in touch and we had a chat about it on IM. He too has written about this issue!

Advertisements

13 thoughts on “Java update broke my Maven

  1. Instead of a symlink, you might just put the maven bin in your path before /usr/bin. As a rule, I don’t like to muck with the default OS X install… e.g.:

    export M2_HOME=/usr/local/apache-maven-2.2.1
    export PATH=$M2_HOME/bin:$PATH

  2. I used to do that, I can’t remember the reason why I switched, maybe it was because Apple started shipping Maven2? I’ll probably switch back to that approach to save future headaches like these. Everyone, follow Lance’s tip!

  3. James Stansell says:

    Maven 3 is good stuff. I’ve been using it for all my local builds for at least 3 months now. Of course, I have to follow Lance’s tip to get 3.0.3 at the command line. 🙂

    The modeshape project saw about a 30% speed improvement when they switched to maven 3.
    https://issues.jboss.org/browse/MODE-1096

    Regards,

    -james.

  4. phoenix says:

    Hi
    I had exactly the same results as:

    [steve-imac:/usr/bin]$ ls -la | grep mvn
    lrwxr-xr-x 1 root wheel 24 9 Mar 14:43 mvn -> /usr/share/maven/bin/mvn
    [steve-imac:/usr/bin]$ cd /usr/share/
    [steve-imac:/usr/share]$ ls -la maven
    lrwxr-xr-x 1 root wheel 16 9 Mar 14:43 maven -> java/maven-3.0.2

    However I don’t see a /user/local/ – the directory doesnt exist. I tried Lance’s suggestion but using share instead of local.
    I tried setting:
    export M2_HOME=”usr/share/java/maven-3.0.2/bin/mvn” (*and without the /bin/mvn)
    export PATH=$M2_HOME:$PATH (*with PATH=$M2_HOME/bin:$PATH)
    I still get the same error. Also this doesnt persist with another terminal so
    1) why do I only see share and not local even with ls -la
    2) how come I still get the same error “Exception in main thread…etc”
    3) how do I persist the path when I do get the right setting in every terminal

    Help would be grately appreciated. I would like to use the 3.0.2 as I have nothing really dependent on the 2.2.1 although it would be nice to switch between the 2 if I knew how.

    Thanks

    • Hi,
      Can you paste your results of the commands I ran above? The goal is to trace through the symlinks the actual path to the installed version of Maven so that then we can upgrade it.

      The other (easier) option is just to install the version of Maven you want, and then add it to your PATH before /usr/bin, as Lance described.

      The way you persist it is via adding it to your .profile:

      export M2_HOME=/path/to/your/preferred/maven/installation

      export $M2_HOME/bin:$PATH

      • phoenix says:

        Hi the results are as I stated – your results exactly!

        The result of typing mvn still produces the output
        Exception in thread “main” java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
        Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

        I suspect I have to delete a softlink but the solution here seems confusing. First it was to delete the softlink and create a new one :
        sudo rm /usr/bin/mvn
        sudo ln -s /usr/local/apache-maven-2.2.1/bin/mvn /usr/bin/mvn

        however I do not have /usr/local
        I have usr/share/maven

        The next suggestion was to do Lance’s suggestion of export.

        I would like to be able to switch between maven versions but atm I am not too bothered if I use the version 3.0.2.
        Therefore if I follow your example would I do?
        rm /usr/bin/mvn
        sudo ln -s /usr/share/maven/maven-3.0.2/bin/mvn usr/bin/mvn

        but not sure how I could switch between versions. I wrote an M2_HOME variable that points to /usr/share/maven/maven-3.0.2 ( I think – Im not with my mac right now)

        not sure if thats confused things a little!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s