2016-05-27 24 views
1

我按照這個教程: https://jersey.java.net/documentation/latest/getting-started.html 這是我的pom.xml文件:'dependencies.dependency.version' 的org.glassfish.jersey.containers:新澤西州容器grizzly2-HTTP:罐子缺少

<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>com.example</groupId> 
    <artifactId>simple-service</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>simple-service</name> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.glassfish.jersey</groupId> 
       <artifactId>jersey-bom</artifactId> 
       <version>${jersey.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-grizzly2-http</artifactId> 
     </dependency> 
     <!-- uncomment this to get JSON support: 
     <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-moxy</artifactId> 
     </dependency> 
     --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.9</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <inherited>true</inherited> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <mainClass>com.example.Main</mainClass> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <properties> 
     <jersey.version>2.23</jersey.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <repositories> 
     <repository> 
      <id>snapshot-repository.java.net</id> 
      <name>Java.net Snapshot Repository for Maven</name> 
      <url>https://maven.java.net/content/repositories/snapshots/</url> 
      <layout>default</layout> 
     </repository> 
    </repositories> 
</project> 

我已經遇到這個錯誤:

'dependencies.dependency.version' for org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar is missing

enter image description here

幫我解決問題。

+0

我已經複製你的pom.xml,並嘗試'mvn validate',它的工作原理。請確認您使用的是最新版本的Maven。另外,請嘗試從命令行執行此操作 - NetBeans可能會干擾Maven。 –

+0

我使用最新版本的Maven,此時'3.3.9'。 –

+0

我剛剛看到NetBeans捆綁了一些Maven版本。你在使用捆綁的嗎?它是相同的版本嗎? 最重要的是,當您從命令行執行'mvn -V validate'時,您是否看到相同的版本和相同的錯誤? –

回答

1

您需要添加在你的依賴聲明版本信息:

例:

<dependency> 
    <groupId>org.glassfish.jersey.containers</groupId> 
    <artifactId>jersey-container-grizzly2-http</artifactId> 
    <version>2.21</version> 
</dependency> 
+2

爲了避免設置版本,他特意加入了一個'bom'。結帳這[SO帖](http://stackoverflow.com/questions/22870422/what-is-the-purpose-of-including-the-jersey-bom-import-scoped-dependency-in-a-je)。 – Abhishek

+0

對不起,我的壞。這是非常有趣的帖子,每天都有東西需要學習:) – Helios

1

我這些刪除評論:

<dependency> 
    <groupId>org.glassfish.jersey.media</groupId> 
    <artifactId>jersey-media-moxy</artifactId> 
</dependency> 

然後它工作。這是示例源代碼中的缺陷。