1

I have an application which has depenendencies to many applications using log4j.

When I run that application with

mvn exec:java 

everything works fine, but when I want to run it as a standalone java application by using

java -jar

I get many errors:

ERROR StatusLogger Unrecognized format specifier [d]
...

The reason is that the log4j2 configuration can not be found.

I know that there is an solution for that issue on

Log4j2 configuration not found when running standalone application builded by shade plugin

but I do use the maven assembly plugin and not the maven shade plugin so that I can not use that transformer. Besides I would really like to understand that problem in detail. How can it be possbile that the maven command works and that second java command does not?

Any help would be really appreciated

Thanks

shakachuk
  • 59
  • 6

3 Answers3

1

When you run it as mvn exec:java, Maven takes care of the classpath. Your jar probably doesn't include that config file. Try adding that config file to your classpath with -cp argument.

Suneel
  • 817
  • 3
  • 10
  • 23
  • I am not very familiar with the classpath. The problem is that I am not sure for which log4j property the application is exactly looking. Is it possible to give him something like a parent folder so that he can catch any configuration file that he needs, or is this not the way it is supposed to work – shakachuk Aug 16 '17 at 18:22
  • Actually there is a log4j property in that jar, nevertheless it does not work. log4j is not able to find that log :( – shakachuk Aug 16 '17 at 18:52
  • Log4j uses an order for looking up the config file. It looks like when you run in Maven, it is picking up a different file for configuration file from classpath. Without maven, it is using the log4j file from your jar. See here for automatic log4j configuration rules: https://logging.apache.org/log4j/2.0/manual/configuration.html – Suneel Aug 16 '17 at 21:00
0

I've seen that Unrecognized format specifier error when there were multiple versions of Log4j2 on the classpath. What's in the jar you're trying to execute? Please verify it contains only the classes for no more than one Log4j2 version.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
0

Please see my answer here. This happens because the generated jar doens't include the .dat file required by log4j2.

fssilva
  • 995
  • 11
  • 7