Maven:package com.sun.istack.internal不存在。

6

我有一个小的maven项目,使用了com.sun.istack.internal.Nullable。

我尝试过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

1
你测试过这个依赖吗? com.sun.istack istack-commons-tools 3.0.5 - Amir Azizkhani
1
但是它们仍然没有提供必要的一个,并且他们永远不会。猜猜为什么软件包名称com.sun.istack.internalinternal结尾。 - Holger
2个回答

14

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

然后添加此依赖项:

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

2
有一个与 @NotNull 相关的问题,import org.jetbrains.annotations.NotNull 解决了这个问题。 - Clodéric
那个是用于内部使用的。 - Aunmag
@Aunmag 我之前在我的测试案例中一直在使用它,但我做了几个更改后,它才开始报错。我认为这个“那个是用于内部使用”的说法不适用。 - Farid

0
在我的情况下,我遇到了这个问题,因为我将Spring启动器父级更新到3.X.X版本和Java版本17。在这种情况下,我使用jakarta.validation.constraints.NotNull来解决。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接