macos 您如何解决 Mac OS X 中 JDK 中缺少 tools.jar 的问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5616318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:56:29  来源:igfitidea点击:

How do you address the issue of a missing tools.jar in a JDK in Mac OS X?

javamacostomcatjakarta-ee

提问by Nikki Erwin Ramirez

From my searching, I found supporting information here: Java Development Guide for Mac OS X

从我的搜索中,我在这里找到了支持信息: Mac OS X 的 Java 开发指南

tools.jardoes not exist. Classes usually located here are instead included in classes.jar. Scripts that rely on the existence of tools.jarneed to be rewritten accordingly.

tools.jar不存在。通常位于此处的类被包含在classes.jar. 依赖于存在的脚本tools.jar需要相应地重写。

If a rewrite is inevitable, how does that go?

如果重写是不可避免的,那怎么办?

This problem was encountered while deploying on Tomcat 6 installed via MacPorts on a Mac OS X 10.6 machine.

在 Mac OS X 10.6 机器上通过 MacPorts 安装的 Tomcat 6 上进行部署时遇到此问题。

回答by Bruno Jullien

Here is my tested solution, which implies no change in maven config, just add symbolic links:

这是我测试过的解决方案,这意味着 maven 配置没有变化,只需添加符号链接:

  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../Classes/classes.jar /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../Classes/tools.jar
  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../Classes /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../lib
  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../Classes/classes.jar /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents /Home/../Classes/tools.jar
  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../Classes /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/. ./lib

Enjoy! Bruno

享受!布鲁诺

回答by Ray Hunter

This is similar to Bruno's answer above; however, I am not a big fan of symlinking the absolute path. Here is how I handle the symlinks:

这类似于上面布鲁诺的回答;然而,我不是符号链接绝对路径的忠实粉丝。这是我处理符号链接的方式:

cd /Library/Java/JavaVirtualMachines/<jdk version>/Contents/Home
sudo ln -s lib Classes

cd lib/
sudo ln -s tools.jar classes.jar

That makes it easier then symlinking absolute paths.

这使得符号链接绝对路径更容易。

回答by user unknown

Well, you search for 'tools.jar', with grep for instance. If the place where classes.jar is, where tools.jar was expected, you could just change the word.

好吧,您搜索“tools.jar”,例如使用 grep。如果 classes.jar 所在的位置,tools.jar 预期的位置,您可以更改单词。

Another idea is, to create a symbolic link from classes.jar to tools.jar, if you have enough privileges and the file system(s) on MacOS support this. Else: copy. Might be more easy, but not be forgotten for updates, maybe.

另一个想法是,创建从 classes.jar 到 tools.jar 的符号链接,如果您有足够的权限并且 MacOS 上的文件系统支持此操作。其他:复制。可能更容易,但不要忘记更新,也许。

回答by sourcedelica

Instead of using Tomcat from Macports download Tomcat from Apache.

从 Apache 下载 Tomcat,而不是从 Macports 使用 Tomcat。

6.0: http://tomcat.apache.org/download-60.cgi

6.0:http: //tomcat.apache.org/download-60.cgi

7.0: http://tomcat.apache.org/download-70.cgi

7.0:http: //tomcat.apache.org/download-70.cgi

回答by Chris Hinshaw

Edit to Bruno's answer which was finally what worked for me after quite a bit of maven trial and error.

编辑布鲁诺的答案,经过相当多的 maven 反复试验后,这最终对我有用。

If you are using 1.7 then you should be able to change revision to 1.7. I do not know if this is still a problem in Java 1.7 though.

如果您使用的是 1.7,那么您应该能够将修订版更改为 1.7。我不知道这在 Java 1.7 中是否仍然是一个问题。

sudo sh -c '$(j_home=$(/usr/libexec/java_home -v 1.6) && ln -sf ${j_home}/../Classes/classes.jar ${j_home}/../Classes/tools.jar && ln -sf ${j_home}/../Classes ${j_home}/../lib)'

回答by tintin

I faced the same problem, and resolved it differently.

我遇到了同样的问题,并以不同的方式解决了它。

  • First check that the java_homeis set as /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contentsand not /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  • Add the cobertura plugin, make sure systemPathis correctly ref the location of classes.jar

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.6</version>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.6</version>
                    <scope>system</scope>
                    <systemPath>${java_home}/Classes/classes.jar</systemPath>
                </dependency>
            </dependencies>
        </plugin>
    
  • Add the dependency and exclude tools

        <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.6</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • Finally add the following profiles

    <profiles>
    <profile>
        <id>standard-jdk</id>
        <activation>
            <file>
                <exists>${java_home}/Home/lib/tools.jar</exists>
            </file>
        </activation>
        <properties>
            <tools-jar>${java_home}/Home/lib/tools.jar</tools-jar>
        </properties>
    </profile>
    <profile>
        <id>apple-jdk</id>
        <activation>
            <file>
                <exists>${java_home}/Classes/classes.jar</exists>
            </file>
        </activation>
        <properties>
            <tools-jar>${java_home}/Classes/classes.jar</tools-jar>
        </properties>
    </profile>
    

  • 首先检查JAVA_HOME设置为 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  • 添加 cobertura 插件,确保systemPath正确引用位置classes.jar

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.6</version>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.6</version>
                    <scope>system</scope>
                    <systemPath>${java_home}/Classes/classes.jar</systemPath>
                </dependency>
            </dependencies>
        </plugin>
    
  • 添加依赖和排除工具

        <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.6</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 最后添加以下配置文件

    <profiles>
    <profile>
        <id>standard-jdk</id>
        <activation>
            <file>
                <exists>${java_home}/Home/lib/tools.jar</exists>
            </file>
        </activation>
        <properties>
            <tools-jar>${java_home}/Home/lib/tools.jar</tools-jar>
        </properties>
    </profile>
    <profile>
        <id>apple-jdk</id>
        <activation>
            <file>
                <exists>${java_home}/Classes/classes.jar</exists>
            </file>
        </activation>
        <properties>
            <tools-jar>${java_home}/Classes/classes.jar</tools-jar>
        </properties>
    </profile>
    

Now run maven and it should successfully generate the Cobertura reports!

现在运行 maven,它应该会成功生成 Cobertura 报告!

回答by Erik Ostermueller

Can't find any references to it on the interweb, but my Mac 1.7 and 1.8 jdk's now have tools.jar.

在互联网上找不到任何对它的引用,但我的 Mac 1.7 和 1.8 jdk 现在有 tools.jar。

/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar

/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/lib/tools.jar /Library/Java /JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1 .8.0_51.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/lib/tools.jar /Library/Java/JavaVirtualMachines/1.6.0.jdk /Contents/Classes/classes.jar

classes.jar is only present in mac 1.6 jdk.

classes.jar 仅存在于 mac 1.6 jdk 中。

--Erik

——埃里克