1

I follow this tutorial: https://jersey.java.net/documentation/latest/getting-started.html this is my pom.xml file:

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

I've been faced this error:

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

enter image description here

Help me resolve problem.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • I have copied your pom.xml and tried `mvn validate` and it works. Please verify you're using latest version of Maven. Also, please try executing this from command line - it's possible that NetBeans somehow interfere with Maven. – Anton Koscejev May 27 '16 at 08:56
  • I use latest version of Maven at this time `3.3.9`. – Vy Do May 27 '16 at 09:25
  • I just read that NetBeans is bundling some version of Maven. Are you using the bundled one? Is it the same version? Most importantly, when you do `mvn -V validate` from command line, do you see the same version and the same error? – Anton Koscejev May 27 '16 at 09:33

2 Answers2

1

You need to add version information in your dependency declaration:

Ex:

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-grizzly2-http</artifactId>
    <version>2.21</version>
</dependency>
Helios
  • 851
  • 2
  • 7
  • 22
  • 2
    He has included a `bom` specifically to avoid setting version. Checkout this [SO post](http://stackoverflow.com/questions/22870422/what-is-the-purpose-of-including-the-jersey-bom-import-scoped-dependency-in-a-je). – Abhishek May 27 '16 at 08:29
  • Yeah sorry my bad. It's really interesting post, there is something to learn everyday :) – Helios May 27 '16 at 08:41
1

I remove comment at these:

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

then it works. This is a defect in the sample source code.

Vy Do
  • 46,709
  • 59
  • 215
  • 313