Druid Maven引入缺少Jconsole.jar和Tools.jar的问题原因及解决办法

/ 默认分类 / 没有评论 / 2006浏览
 Could not resolve dependencies for project com.xxx:xxx-framework🏺3.8.4: The following artifacts could not be resolved: com.sun:tools🏺1.8, com.sun:jconsole🏺1.8: Could not find artifact com.sun:tools🏺1.8 at specified path /root/.m2/repository/com/alibaba/druid/1.2.11/lib/openjdk-1.8-tools.jar 

问题原因

OracleJDK面临商业闭源风险,所以用到的Jconsole和Tools引入的是OpenJDK

openjdk-1.8-jconsole.jar
openjdk-1.8-tools.jar

解决方案

使用OpenJDK


<dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.8</version>
            <scope>system</scope>
            <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency> 
<dependency>
            <groupId>jdk.tools</groupId>
            <artifactId>jdk.tools</artifactId>
            <version>1.8</version>
            <scope>system</scope>
            <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency> 

排除使用

大多数未用到这个功能(未参与源码(开发),则排除即可

<exclusions>
    <exclusion>
        <groupId>com.sun</groupId>
        <artifactId>jconsole</artifactId>
    </exclusion>
    <exclusion>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
    </exclusion>
</exclusions>