编译错误,包javax.ws.rs不存在,无法从Maven解析依赖项 [英] compilation error, package javax.ws.rs does not exist, dependencies not resolved from maven

查看:251
本文介绍了编译错误,包javax.ws.rs不存在,无法从Maven解析依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在pom文件中提到了依赖库,但是库系统路径也存在,但是在使用maven clean install -e -X进行编译的过程中,它抛出错误,表明该软件包不存在.

I had mentioned the dependency libraries in the pom file, also the library system path exists also, but during the compilation using maven clean install -e -X, it throws error saying the package does not exists.

**[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**

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>

推荐答案

您需要在您的POM中包含Java EE依赖项,其作用域为provided(也就是文件最终会 由应用服务器提供,但与此同时我需要它们进行编译).

You need to include the Java EE dependencies in your POM, with a provided scope (aka, the files will eventually be provided by the application server, but in the meantime I need them for compilation).

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

这篇关于编译错误,包javax.ws.rs不存在,无法从Maven解析依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆