【问题标题】:Maven: package com.sun.istack.internal does not existMaven:包 com.sun.istack.internal 不存在
【发布时间】:2017-12-13 12:39:13
【问题描述】:

我有一个使用 com.sun.istack.internal.Nullable 的小 maven 项目。
我尝试了 JDK 9 和 1.8,但仍然收到有关包不存在的错误。 我搜索了包裹并找到了一些:https://mvnrepository.com/search?q=+com.sun.istack,但他们仍然没有提供必要的包裹。

JAVA_HOME:

apshenichnikov@IAS-WS-UX02:~/NetBeansProjects/newlps$ echo $JAVA_HOME
/usr/local/java/jdk1.8.0_121/

还有 JDK:

apshenichnikov@IAS-WS-UX02:~/NetBeansProjects/newlps$ sudo update-alternatives --config java
There are 4 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-9-oracle/bin/java       1091      auto mode
  1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-9-oracle/bin/java       1091      manual mode
* 3            /usr/local/java/jdk1.8.0_121/             1         manual mode
  4            /usr/local/java/jdk1.8.0_121/bin/java     1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

还有 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.beinteractive</groupId>
    <artifactId>newlps</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>newlps</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.google.code.externalsortinginjava</groupId>
            <artifactId>externalsortinginjava</artifactId>
            <version>0.1.9</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <compilerArgument>-XDignore.symbol.file</compilerArgument>
                </configuration>
            </plugin>           
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/libs
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>           
        </plugins>      
    </build>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

我注射了:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
    </configuration>
</plugin>

POM.xml 内部

我还有编译异常

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.286 s
[INFO] Finished at: 2017-12-13T15:28:45+03:00
[INFO] Final Memory: 20M/261M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project newlps: Compilation failure: Compilation failure:
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/ParamUtils.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/StringUtils.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/ParamUtils.java:[36,74] cannot find symbol
[ERROR] symbol:   class Nullable
[ERROR] location: class su.ias.utils.ParamUtils
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/ParamUtils.java:[46,68] cannot find symbol
[ERROR] symbol:   class Nullable
[ERROR] location: class su.ias.utils.ParamUtils
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/StringUtils.java:[19,36] cannot find symbol
[ERROR] symbol:   class Nullable
[ERROR] location: class su.ias.utils.StringUtils
[ERROR] /home/apshenichnikov/NetBeansProjects/newlps/src/main/java/su/ias/utils/StringUtils.java:[45,6] cannot find symbol
[ERROR] symbol:   class Nullable
[ERROR] location: class su.ias.utils.StringUtils
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

【问题讨论】:

  • 你在测试这个依赖&lt;dependency&gt; &lt;groupId&gt;com.sun.istack&lt;/groupId&gt; &lt;artifactId&gt;istack-commons-tools&lt;/artifactId&gt; &lt;version&gt;3.0.5&lt;/version&gt; &lt;/dependency&gt; 吗?
  • “但他们仍然没有提供必要的”……而且他们永远不会。猜猜为什么包名com.sun.istack.internalinternal结尾。

标签: java maven ubuntu java-8 dependencies


【解决方案1】:

尝试导入import org.jetbrains.annotations.Nullable。它与 @Nullable 注释所需的相同。

然后添加这个依赖:

<dependency>
    <groupId>org.jetbrains</groupId>
    <artifactId>annotations</artifactId>
    <version>13.0</version>
</dependency>

【讨论】:

  • @NotNull 有同样的问题,import org.jetbrains.annotations.NotNull 成功了
  • 那是内部使用的
  • @Aunmag 我一直在我的测试用例中使用它,但我做了一些更改,然后才开始抛出错误。我认为这个“那个是内部使用的”不是这样的
猜你喜欢
  • 1970-01-01
  • 2013-02-19
  • 2018-12-23
  • 2021-08-10
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-19
相关资源
最近更新 更多