【问题标题】:Can't run maven install on eclipse anymore (tools.jar not found)无法再在 Eclipse 上运行 Maven 安装(未找到 tools.jar)
【发布时间】:2017-12-18 01:24:45
【问题描述】:

我正在开发 ubuntu 16.04,我有一个无法编译的 Eclipse 项目。每次我尝试我都会遇到这个错误:

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5:compile (default-compile) on project TwavoxManager: Fatal error compiling: tools.jar not found: /usr/lib/jvm/java-8-openjdk-amd64/jre/../lib/tools.jar -> [Help 1]

我首先可以毫无问题地编译它,但我必须在我的系统上重新安装 java (openJDK8)。

我尝试了这个链接Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin (default-compile) on project: Fatal error compiling: tools.jar not found的解决方案

但问题是 openJDK8 有 JDK + JRE 对吗? 我完全迷失了这里

编辑:添加 pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cineapps</groupId>
  <artifactId>TwavoxManager</artifactId>
  <packaging>jar</packaging>

  <name>TwavoxManager</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
        <plugins>
            <!-- COMPILER -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <!-- RESOURCES -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>
            <!-- SHADE -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>TwavoxManager-${project.version}-min</finalName>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>cineapps.TwavoxManager.app.App</mainClass>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/res</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

  <dependencies>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.54</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.miglayout/miglayout-swing -->
<dependency>
    <groupId>com.miglayout</groupId>
    <artifactId>miglayout-swing</artifactId>
    <version>4.2</version>
</dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-net</groupId>
        <artifactId>commons-net</artifactId>
        <version>3.3</version>
    </dependency>
  </dependencies>
  <version>1.0</version>
</project>

编辑:有用的屏幕:

【问题讨论】:

  • 请分享您的 pom.xml 并将项目特定的 JRE 设置为您的项目
  • @Zia 添加了 pom.xml
  • 能否请您修改您的pom中的插件条目,org.apache.maven.pluginsmaven-compiler-plugin3.11.81.8
  • 我现在有这个错误:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project TwavoxManager: Compilation failure [错误] 此环境中未提供编译器。也许您在 JRE 而不是 JDK 上运行?
  • 右击你的项目,Build Path->Configure Build Path。在右侧选项中选择“JRE System Library”选择编辑然后配置你的JDK

标签: java eclipse maven


【解决方案1】:

更新 pom.xml 中的插件条目,

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

并配置项目JDK,

右击你的项目,Build Path->Configure Build Path。在右侧选项中选择“JRE System Library”选择编辑然后配置你的JDK

【讨论】:

  • 它不起作用,我仍然有同样的错误,我在原始帖子中提供了我的 JRE 系统库的屏幕
  • 可能有用,我在终端中运行了 echo£ $JAVA_HOME 并得到了这个:/usr/lib/jvm/java-8-openjdk-amd64/
  • 编辑该 JRE 并查看已安装的 JRE,将其指向您提到的 JDK“/usr/lib/jvm/java-8-openjdk-amd64/”
  • jre 中没有 jdk 文件夹,但我有 java/bin 和 java/jre/bin
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-25
  • 2017-11-11
  • 2011-08-09
  • 2019-02-14
  • 1970-01-01
相关资源
最近更新 更多