编译错误,包javax.ws.rs不存在,依赖关系无法从maven解析

Gop*_*pal 16 maven

我已经提到了pom文件中的依赖库,也存在库系统路径,但是在使用maven clean install -e -X编译期间,它会抛出错误,说包不存在.

**[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[4,19] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:4: package javax.ws.rs does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[5,19] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:5: package javax.ws.rs does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[6,19] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:6: package javax.ws.rs does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[8,1] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:8: package javax.ws.rs.core does not exist
[ERROR] /C:/Users/gopc/workspace/RestfulService/src/restfu/Hello.java:[21,2] C:\Users\gopc\workspace\RestfulService\src\restfu\Hello.java:21: cannot find symbol
symbol: class Path**
Run Code Online (Sandbox Code Playgroud)

POM文件

<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>RestfulService</groupId>
  <artifactId>RestfulService</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>${basedir}/src</sourceDirectory>
    <outputDirectory>${basedir}/build/classes</outputDirectory>
  <pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
</pluginManagement>

</build>

<dependencyManagement>
<dependencies>

  <dependency>
    <groupId>jersey-server</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.4</version>
    <scope>compile</scope>
    <systemPath>${basedir}/lib/jersey-server-1.4.jar</systemPath>
  </dependency>

<dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs</artifactId>
        <version>1.4</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/javax.ws.rs.jar</systemPath>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Run Code Online (Sandbox Code Playgroud)

Per*_*ion 30

您需要在POM中包含Java EE依赖项和provided范围(也就是说,文件最终将由应用程序服务器提供,但在此期间我需要它们进行编译).

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

  • 我已经添加了依赖项,但错误仍然相同。 (2认同)

Nen*_*ena 7

@Perception 回复的依赖也是需要的,但这对我来说还不够。还需要以下依赖项:

\n\n
<dependency>\n    <groupId>javax.ws.rs</groupId>\n    <artifactId>javax.ws.rs-api</artifactId>\n    <version>2.0</version>\n</dependency>\n
Run Code Online (Sandbox Code Playgroud)\n\n

https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api/2.0

\n\n

\xce\xa4his 帮我解决了问题!

\n


4pi*_*ie0 5

系统更新后,当NetBeans更改字体和GUI时,我遇到了更多类似的问题.我已经通过添加Java EE 6 API LibraryNetBeans IDE 解决了这个问题

myProject->Properties->Libraries->Add Library