0

I have been trying to add this to my POM file which is what is in an example POM file for a hello world program:

<!-- Import the Common Annotations API (JSR-250), we use provided scope 
     as the API is included in JBoss AS 7 -->
  <dependency>
     <groupId>org.jboss.spec.javax.annotation</groupId>
     <artifactId>jboss-annotations-api_1.1_spec</artifactId>
     <scope>provided</scope>
  </dependency>

When I run it, it fails. It says the version number is missing. When I add a version, say 1.0, it still fails. I am pretty new to POM files and maven, so any explanation would be helpful.

My POM 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.unihub.app</groupId>
  <artifactId>unihub</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>unihub</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
<!--Import the Servlet API using provided scope as the JARs are already included in Jboss7-->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>
     <build>
      <!-- Set the name of the war, used as the context root when the app 
         is deployed -->
      <finalName>unihub</finalName>
      <plugins>
               <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>7.3.Final</version>
         </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.1</version>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>
          </configuration>
        </plugin>
       </plugins>
   </build>
</project>
Andy
  • 10,553
  • 21
  • 75
  • 125

1 Answers1

2

For a maven dependency, you have to get to know which version is available.

You can either browse the repository you are using, or search it on the web.

For instance : http://mvnrepository.com/artifact/org.jboss.spec.javax.annotation/jboss-annotations-api_1.1_spec

shows that 1.0.1.Final is a valid version.

Samuel EUSTACHI
  • 3,116
  • 19
  • 24
  • Hmm, I have tried it before and it failed. But I never put the Final at the end. I just did and it worked. I am confused as to why it fails if I dont append Final like `1.0.1.Final`? – Andy Feb 20 '13 at 07:05
  • the Whole String defines the version. 1.0.1.Final would be different from 1.0.1.RC, for instance (here RC would stand for Release candidate, but you can really have anything) – Samuel EUSTACHI Feb 20 '13 at 07:07
  • The link I posted is a nice example, as clearly 1.0.0.FINAL is not the same artefact as 1.0.0.BETA1 – Samuel EUSTACHI Feb 20 '13 at 07:09
  • Thanks a lot! Do you recommend any good tutorials on understanding maven POM files? But if not its ok. You've been a big help. – Andy Feb 20 '13 at 07:10
  • The official doc is ok. http://maven.apache.org/pom.html I also bought this book, nice if you want to dig further : http://www.amazon.com/Maven-Definitive-Guide-Sonatype-Company/dp/0596517335#reader_0596517335 – Samuel EUSTACHI Feb 20 '13 at 07:15
  • You can also take a look at your .m2 folder. It helps to realite how maven works locally. You will see that you probably have some empty folders, one for each failing attempt to get a wrong version of the lib (known maven issue, see http://stackoverflow.com/questions/8857985/compiler-error-archive-for-required-library-could-not-be-read-spring-tool-su/10123184#10123184 ) This is something to know, as you will probably have the same problem as soon as you use modules projects – Samuel EUSTACHI Feb 20 '13 at 07:20