10
votes

I'm new to Maven, and struggling with adding dependencies. I'm trying to convert an existing project to Maven, and after adding the dependencies for all the jars in my referenced libraries, I'm receiving an error message about missing artifacts:

Missing artifact stax:stax:jar:1.0    
Missing artifact clover:clover:jar:1.3-rc4
Missing artifact log4j:log4j:bundle:1.2.16
Missing artifact stax:stax-ri:jar:1.0

From reading this post: How to handle Maven missing artifact errors?, it sounds like I need to manually download these jars and add them to my local maven repository. My question is how do I find these jars? I tried googling them, and I can find jars that have similar names, but not exactly like these, so I'm not sure if they're the right jars.

Any tips for dealing with this problem? The log4j jar is the only one explicitly listed in the referenced libraries of my original project, so I'm guessing the other ones are required by other jars that I have, and I don't know where to find them or what their exact names should be.

Thanks!

9
If you use maven and have to download artifacts manually, you are doing something seriously wrong. Post your pom.xml or the relevant parts of it.j13r
That's what I was thinking as well...The POM created by the Eclipse m2e plugin had several problems, see my answer below for the description of the problems.matthewb

9 Answers

21
votes

Thanks to everyone for responding. The actual cause of the problem is that for each of those 3 missing artifacts, for some reason, when Maven downloaded them into my local repository, .lastUpdated was appended to the end of the jar. For example, stax-1.0.jar.lastUpdated. This is the reason Maven could not find stax-1.0.jar.

So, to fix this problem, I had to manually download stax-1.0.jar, then install it into the local maven repository in the exact same place as the messed up file, so that Maven could find it. (For example, using the command:

mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar         
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar

Using the same exact groupId and artifactId as the existing, incorrect file was crucial in order for maven to find it.

2
votes

You can find dependency search Sites under maven.apache.org. Go to the left side Navigation Menü entry FAQ (official) and Thun to end of page.

1
votes

It's more likely that your POM definition is not correct for log4j. Everything relating to log4j should be readily available in maven.

Also, if you know the name of the bundle (such as log4j) you can almost always do a quick google search "[bundle name] maven pom" within the first few hits you should either get the maven repo containing a quick snippet on how to include it, or the actual website for the bundled up jar and the maven instructions.

For example log4j:

<dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
</dependencies> 

Sometimes though you just need to specify the repository to find the item in (if it's not hosted in the greater maven repositories)

You can specify a new repository like so

<repositories>
    <repository>
        <id>Java.Net</id>
        <url>http://download.java.net/maven/2/</url>
    </repository>
</repositories>

Finally when you absolutely cannot find the artifact already maven'd up for you (this is usually true for proprietary jars and or drivers that you cannot include with your project) you can have the user manually install the item via command line

mvn install:install-file -DgroupId=[group-id] -DartifactId=[artifact-id] -Dversion=[version] -Dfile=/path/to/the/file -Dpackaging=[type]

You can then reference it in your maven file using the information described above

For example I have a custom reference for a salesforce.com project

mvn install:install-file -DgroupId=com.salesforce -DartifactId=wsc -Dversion=22 -Dfile=\tsclient\H\development\java\wsc-22.jar -Dpackaging=jar

To access it in maven:

<dependency>
    <groupId>com.salesforce</groupId>
    <artifactId>wsc</artifactId>
    <version>22</version>
</dependency>

Finally, you can find the jars (or their maven info) at their respective websites (please note I'm just basing these links off the jar names, these may not be the actual websites, well sans the log4j which I know to be correct)

Stax

Clover

Log4j

1
votes

you can try to add new repositories to your pom.xml

<repositories>
     <repository>
    <id>java.net</id>
    <url>http://download.java.net/maven/2/</url>
    </repository>
      <repository>
        <id>jboss</id>
        <url>http://repository.jboss.com/maven2</url>
 </repository>
</repositories>
1
votes

After several days this stupid error bugged me, I found the following article

The author describes that there is a workspace repository, which may out of date. In my case it helped just to import the correct plugins again. The workspace repository has been updated and everything is fine.

0
votes

Your problem might be something to do with MNG-4142. This bug means that maven will not download a new snapshot if localCopy is set to true in the artifact maven-metadata-local.xml.

Note that the title of this bug is slightly misleading so it is work reading the comments.

You might think that using the -U flag with maven would fix this problem but apparently this is not the case.

The current workaround seems to be searching for all instances of maven-metadata-local.xml and changing the value of localCopy to false.

0
votes

I solved this problem by changing the log4j version from 1.2.15 to 1.2.16.

0
votes

It also could be cause by the dom4j. The same error occurred when I use the following settings.

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>20040902.021138</version>
</dependency>

After changing to the following, the error disappeared.

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>