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

发布于 2024-10-31 15:02:52 字数 433 浏览 1 评论 0原文

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

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

如果重写是不可避免的,那会怎样呢?

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

女皇必胜 2024-11-07 15:02:52

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

  • ln -s /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../Classes/classes。罐
    /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/../课程
    /Library/Java/JavaVirtualMachines/1.6.0_38-b04-436.jdk/Contents/Home/../lib

享受吧!
布鲁诺

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

  • 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

国产ˉ祖宗 2024-11-07 15:02:52

这与上面布鲁诺的回答类似;然而,我不太喜欢符号链接绝对路径。这是我处理符号链接的方法:

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

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

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

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.

旧人九事 2024-11-07 15:02:52

好吧,您可以使用 grep 等搜索“tools.jar”。如果classes.jar 所在的位置是tools.jar 所在的位置,则只需更改该单词即可。

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

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.

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.

〃温暖了心ぐ 2024-11-07 15:02:52

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

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

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

Instead of using Tomcat from Macports download Tomcat from Apache.

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

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

ら栖息 2024-11-07 15:02:52

编辑布鲁诺的答案,经过相当多的行家试验和错误后,这最终对我有用。

如果您使用的是 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)'

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

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.

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)'
溇涏 2024-11-07 15:02:52

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

  • 首先检查 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

    <前><代码> <插件>
    org.codehaus.mojo;
    cobertura-maven-plugin;
    <版本>2.6
    <依赖关系>
    <依赖关系>
    com.sun;
    工具
    <版本>1.6
    <范围>系统
    ${java_home}/Classes/classes.jar


  • 添加依赖项并排除工具

     <依赖项>
        org.codehaus.mojo;
        cobertura-maven-plugin;
        <版本>2.6
        <范围>测试
        <排除>
            <排除>
                com.sun;
                工具
            
        
    
    
  • 最后添加以下配置文件

    <前><代码><配置文件>;
    <简介>
    标准jdk
    <激活>
    <文件>
    <存在>${java_home}/Home/lib/tools.jar


    <属性>
    ${java_home}/Home/lib/tools.jar


    <简介>
    apple-jdk
    <激活>
    <文件>
    <存在>${java_home}/Classes/classes.jar


    <属性>
    ${java_home}/Classes/classes.jar

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

I faced the same problem, and resolved it differently.

  • First check that the java_home is set as
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents and not
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  • Add the cobertura plugin, make sure systemPath is 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>
    

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

软甜啾 2024-11-07 15:02:52

在互联网上找不到任何对它的引用,但我的 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

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

——埃里克

Can't find any references to it on the interweb, but my Mac 1.7 and 1.8 jdk's now have 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

classes.jar is only present in mac 1.6 jdk.

--Erik

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文