Builds failing after upgrading to Java7, Missing Tools.jar and bad class versions

后端 未结 8 1698
滥情空心
滥情空心 2020-12-08 17:55

I recently upgraded to Java7 on my Macbook Pro. I downloaded the JDK (not the JRE).

» javac version
javac 1.7.0_17

» echo $JAVA_HOME    
/Library/Java/Java         


        
相关标签:
8条回答
  • 2020-12-08 18:20

    I got the following error on a maven project: Failed to execute goal on project cobertura-maven-plugin: Could not resolve dependencies for project org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.6: Could not find artifact com.sun:tools:jar:0 at specified path /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../lib/tools.jar -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project cobertura-maven-plugin: Could not resolve dependencies for project org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.6: Could not find artifact com.sun:tools:jar:0 at specified path /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../lib/tools.jar

    I fixed it by creating a lib dir under /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents and adding tools.jar to it.

    Full path would be this for tools.jar in this particular instance: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/lib/tools.jar

    0 讨论(0)
  • 2020-12-08 18:22

    Most probably javac is running from JRE and not JDK. tools.jar is only available in JDK. Confirm the path of javac/java by using which

    which javac
    

    Drag correct Java7 version to top in Java Preferences (Launchapad/Others). That should point A to JDK7.

    0 讨论(0)
  • 2020-12-08 18:27

    The correct way to set JAVA_HOME on MacOS X is to use:

    [user@ip ~]$ export JAVA_HOME=$(/usr/libexec/java_home -v1.7)
    [user@ip ~]$ echo $JAVA_HOME 
    /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
    

    Your java installation is broken if, after doing this, $JAVA_HOME/lib does not contain a tools.jar.

    Tip: I have these two aliases specified in my ~/.bash_profile:

    alias java6="export JAVA_HOME=$(/usr/libexec/java_home -v1.6)"  
    alias java7="export JAVA_HOME=$(/usr/libexec/java_home -v1.7)"
    

    Placing jars in /Library/Java/Extensions is equivalent to putting them in the global classpath and is rarely a good idea.

    0 讨论(0)
  • 2020-12-08 18:27

    Forget Maven.

    What directory has the JDK /bin directory? That's JAVA_HOME.

    I suspect that you've set the environment variable incorrectly.

    And that /bin ought to have all the executables for the JDK tools: javac, java, jar, javap, etc.

    If that's not the case, then you don't have JDK, you've got JRE.

    I've got a Windows machine. Here's where I have JDK installed:

    C:\Program Files\Java\jdk1.7.0_17
    

    And here's JAVA_HOME:

    JAVA_HOME=C:/Program Files/Java/jdk1.7.0_02
    
    0 讨论(0)
  • 2020-12-08 18:29

    I found a tools.jar sitting in /Library/Java/Extensions

    I'm not sure if this is standard or not.

    However, copying the tools.jar from the JDK7 $JAVA_HOME/lib to /Library/Java/Extensions solved all my problems.

    I should also point out that in my original question I had updated the Java CurrentSDK to point to JDK7:

    CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents
    

    This was a Bad Idea, as pointed out here.

    I updated this to point back to 1.6. Although this seems counter-intuitive, it was required to get things working.

    The current listing of /System/Library/Frameworks/JavaVM.framework/Versions with a 1.7 JDK looks as follows:

    lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.6.0 -> CurrentJDK
    lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.6 -> CurrentJDK
    lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.5.0 -> CurrentJDK
    lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.5 -> CurrentJDK
    lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.4.2 -> CurrentJDK
    lrwxr-xr-x   1 root  wheel   10 18 Feb 08:36 1.4 -> CurrentJDK
    drwxr-xr-x   8 root  wheel  272 18 Feb 08:39 A
    drwxr-xr-x  11 root  wheel  374 18 Feb 08:39 ..
    lrwxr-xr-x   1 root  wheel    1 14 Jun 11:35 Current -> A
    lrwxr-xr-x   1 root  wheel   59 14 Jun 12:31 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
    drwxr-xr-x  11 root  wheel  374 14 Jun 12:31 .
    
    0 讨论(0)
  • 2020-12-08 18:35

    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    Maven build failure in eclipse with above error was fixed by un-installing older version of java.

    0 讨论(0)
提交回复
热议问题