5

I implemented my own Maven plugin mojo in which I used log4j + slf4j. In the plugin project I have included the correct jars and can see correct logging of statements from code.

Now I want use this new maven plugin in another client project but having trouble getting it to work correctly.

In the plugin itself I have included a log4j.properties under src/main/resources which works fine as mentioned above. But when I try to include the plugin in another client project the log file is not being created.

The question is what else do I have to try or do to get this working correctly? Thank you.

jakstack
  • 2,143
  • 3
  • 20
  • 37
  • 1
    "in another client project", is this a separate project or does it use the Maven Embedder? The plugin doesn't work standalone, it requires a framework for the DI. Also read http://maven.apache.org/maven-logging.html for other options. – Robert Scholte Jan 03 '14 at 10:59
  • Thanks Robert, the client project is simply another maven project with its own pom file that needs to use the custom plugin. Also I don't wish to change Maven's default logging configuration and setup but I do want my custom plugin to have its own logging configuration an setup so not sure the link you suggest helps me in this case. – jakstack Jan 03 '14 at 20:41
  • I've the same problem using Maven 3.5 that statements logged using `getLog` in the plugin don't show up when the plugin is used in another project. What did you end up doing? – Abhijit Sarkar Aug 12 '17 at 17:45

1 Answers1

2

You must not put log4j.properties into src/main/resources.

Log4j will look just for a single log4j.properties resource on the classpath, so depending on the order of elements on the classpath, either your code or the other project will win.

You can put this resource on the test classpath so your tests work correctly.

For the final application, you must load the file from somewhere else or create a kind of "application" Maven project which just contains dependencies, the code of main(), and config files.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820