55

I have created simple project from maven-achetype-quickstart under Eclipse Indigo, then I went to pom.xml gui editor and in dependencies tab added dependency log4j by search in appropriate dialog. Now my pom.xml looks like

<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-.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
  <artifactId>Test_Maven_03</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Test_Maven_03</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
    </dependency>
  </dependencies>
  <dependencyManagement>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
    </dependency>
</dependencies>
  </dependencyManagement>
</project>

Eclipse says my POM have many problems like

Missing artifact javax.jms:jms:jar:1.1 pom.xml /Test_Maven_03 line 2 Maven Dependency Problem

What does it mean and how to see maven feature of automatic jar downloading.

EDIT 1 If I select log4j 1.2.16 instead of 1.2.15, I get another error: Missing artifact log4j:log4j:bundle:1.2.16. So I see no automatic jar management at all.

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • SBT users: ```libraryDependencies += "log4j" % "log4j" % "1.2.15" exclude("javax.jms", "jms")``` – opyate Jan 06 '15 at 13:50

4 Answers4

108

It's not included anymore due to licensing issues if I remember correctly. If you don't need jms functionality you can exclude jms from log4j dependency:

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
    <exclusion>
        <groupId>com.sun.jmx</groupId>
        <artifactId>jmxri</artifactId>
    </exclusion>
    <exclusion>
        <groupId>com.sun.jdmk</groupId>
        <artifactId>jmxtools</artifactId>
    </exclusion>
    <exclusion>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
    </exclusion>
</exclusions>
</dependency>
Sbhklr
  • 2,693
  • 1
  • 17
  • 20
  • 1
    I don't want to do this. I was thinking Maven will handle jars automatically. Without Maven I would just download log4j jar and put it on classpath. With Maven I should guess about licensing... – Suzan Cioc Jan 28 '12 at 19:40
  • Maven will download the dependent jars for you and put it in the class path, but this jar was removed from the repository, have a look at this post: http://stackoverflow.com/questions/4908651/help-the-following-artifacts-could-not-be-resolved-javax-jmsjmsjar1-1 – Sbhklr Jan 28 '12 at 19:46
  • @SuzanCioc Not really true; a dependency is a dependency, regardless of whether you manage it manually or let something else manage it. Although I'm not sure why it complains about a missing dependency; it should get it from the geronimo package. – Dave Newton Jan 28 '12 at 19:47
  • 2
    @Lightforce Don't need to do all this for 1.2.16. – Dave Newton Jan 28 '12 at 19:55
  • @Lightforce can you give me any simple example of Maven work? I can't see any yet. The very first simple example have failed, the very second have failed too. Which jars Maven can handle smoothly? – Suzan Cioc Jan 28 '12 at 20:04
  • @Dave Newton, I have downloaded log4j-1.2.15.jar from repository manually, attached it to my simplistic hello world program and it worked without any problems. So this was Maven who creates problems, not real dependency. – Suzan Cioc Jan 28 '12 at 20:15
  • @SuzanCioc Congratulations on compiling your project with a single dependency. Now do the same thing for a real project. (And build the project's website, run the tests automatically, etc.) You've completely missed the point and believe that a micro-benchmark is an adequate test. – Dave Newton Jan 28 '12 at 20:18
  • @Dave, what is wrong with log4j-1.2.15.jar then if it compiled ok? What problem Maven was reporting? – Suzan Cioc Jan 28 '12 at 20:22
  • 2
    @SuzanCioc You were told what's wrong with Log4J 1.2.15; its Maven metadata points to a dependency that is no longer in the Maven repository. If your simplistic sample doesn't use the functionality of Log4J that requires JMS, then of course your app will compile--Java runtime dependencies are reconciled at runtime, not compile time. If nothing you're compiling depends on a class not present in the compilation classpath, and nothing depends on a runtime class that isn't present, there won't be any issues. – Dave Newton Jan 28 '12 at 20:25
46

Change the version of log4j to 1.2.16.

The metadata for 1.2.15 is bad, as you have discovered, because the dependencies are missing from the central repository. However, there is a policy of not changing artifacts or metadata in the central maven repository, because this can lead to builds being unrepeatable. That is, a build might behave differently if an artifact or its metadata changed.

The reasoning is that it's better to work around bad metadata than cause unreproducible builds.

It's better, of course, if project maintainers are more careful about the metadata that they upload to central.

Martin Ellis
  • 9,603
  • 42
  • 53
  • I am new to Maven and was thinking it provides automatic JAR dependency management. But as I see it doesn't. If I select 1.2.16 I get another error (will edit my post now). So what is the purpose of Maven? Isn't it easier to download jars manually than do police investigation of each Maven kicking up? – Suzan Cioc Jan 28 '12 at 19:59
  • @SuzanCioc There is no way doing manual transitive dependency management is easier than using a tool; don't be ridiculous. A real project may have a hundred dependencies--how will you track those dependencies by hand? When you upgrade something?! Is it *100%* effective? Not always. Geez. – Dave Newton Jan 28 '12 at 20:07
  • So there is no simple way to see Maven work? It can be visible only if hundreds of jars, right? – Suzan Cioc Jan 28 '12 at 20:18
  • log4j is a library that is very careful with its minor versions, so they are almost always drop-in replacements – Arnaud Jeansen Feb 13 '18 at 16:33
13

Use Log4J 1.2.16 (the one I linked to in your earlier question); it doesn't have the older JMX dependency and gets it from Geronimo instead.

Paul Richter
  • 10,908
  • 10
  • 52
  • 85
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • I tried 1.2.16 first as you said, but got another error ('Missing artifact log4j:log4j:bundle:1.2.16'). This is why I started trying another versions. Anyway I see no automation here. If Maven provide such an automation it would say everything about dependencies IMHO. – Suzan Cioc Jan 28 '12 at 19:56
  • @SuzanCioc With [this pom.xml](https://gist.github.com/1695599) and Maven 3 it works fine; you're breaking stuff up into two chunks for no reason I can tell. Just because you aren't currently able to get Maven working doesn't mean it doesn't work. – Dave Newton Jan 28 '12 at 20:06
  • with which of my poms it works? So this is an Eclipse bug or something? – Suzan Cioc Jan 28 '12 at 20:19
  • 1
    @SuzanCioc Your original pom, using Log4J 1.2.16, works fine, as does the one I linked to. I cannot see what's happening in your Eclipse, nor can I reproduce the problem. That said, I don't find Eclipse/Maven integration particularly robust, and when using Eclipse, I do all my Maven work from the command line. – Dave Newton Jan 28 '12 at 20:22
  • this means that the problem was not imagined by me. With the only addition that it relates not with maven, but with eclipse or maven plugin. – Suzan Cioc Jan 28 '12 at 20:25
  • @SuzanCioc if you're using Eclipse m2e plugin for maven, it sometimes gets the type of a dependency as **bundle** whereas it should have actually been **jar**. If you change the type of the dependency from **bundle** to **jar**, it is going to work. – Kaan Aug 14 '12 at 10:22
  • Thanks Dave, Solved my problem. – Chetan S. Choudhary Oct 13 '16 at 07:01
3

The answers above (excluding JMX) are fine, so long as you don't need any of the JMX dependencies. However, you will never be able to download the JMX dependencies' .jar files from a standard maven repository. To quote Jörg Schaible-3 at nabble.com:

This is normal and it will stay so, because Sun/Oracle never granted distribution rights for those artifacts as separate downloads. You will have to download them from Oracle, accepting their license, and add them to a local repository manager.

Therefore, if you want to use JMX, you will need to download the respective jmx zip folder from Oracle's website.

gladclef
  • 31
  • 2