[ 
https://issues.apache.org/jira/browse/LOG4J2-2773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17041521#comment-17041521
 ] 

Ralph Goers edited comment on LOG4J2-2773 at 2/21/20 3:59 AM:
--------------------------------------------------------------

This problem was rather simple to solve for me. I modified the assembly 
configuration as 
{code:java}
<archive>
  <manifestEntries>
    <Multi-Release>true</Multi-Release>
  </manifestEntries>
  <manifest>
    <mainClass>com.test.App</mainClass>
    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
  </manifest>
</archive>{code}
and it started working for me. Note that you may have other problems creating 
an uber jar with the assembly plugin. You would be better off using the Maven 
Shade Plugin as it has a transformer that can combine plugin definitions from 
multiple jars.


!image-2020-02-20-20-59-42-991.png!


was (Author: [email protected]):
This problem was rather simple to solve for me. I modified the assembly 
configuration as 
{code:java}
<archive>
  <manifestEntries>
    <Multi-Release>true</Multi-Release>
  </manifestEntries>
  <manifest>
    <mainClass>com.test.App</mainClass>
    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
  </manifest>
</archive>{code}
and it started working for me. Note that you may have other problems creating 
an uber jar with the assembly plugin. You would be better off using the Maven 
Shade Plugin as it has a transformer that can combine plugin definitions from 
multiple jars.

> Configuration file loading ignored on jar-with-dependencies with java 11
> ------------------------------------------------------------------------
>
>                 Key: LOG4J2-2773
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2773
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.12.1, 2.13.0
>         Environment: openjdk version 11.0.6; Apache Maven 3.6.3; Ubuntu 19.10
>            Reporter: SkyghiS
>            Assignee: Ralph Goers
>            Priority: Major
>         Attachments: image-2020-02-06-21-20-15-004.png, 
> image-2020-02-06-21-21-14-488.png, image-2020-02-20-20-59-42-991.png, java 
> 8.png
>
>
> {quote}Sample project to ease reproduction : 
> [https://github.com/skyghis/testLog4j2]
> {quote}
>  
> I try to load configuration from an external file on a fat jar.
> I tried to load configuration from multiples methods without success.
> I kept two methods on my sample:
> {code:java}
> if (!Files.isReadable(log4jConfiguration)) {
>     throw new IllegalStateException();
> }
> LOGGER.info("startup");
> LOGGER.debug("startup"); // Not logged = OK
> // First try to load configuration
> Configurator.initialize(null, log4jConfiguration.toString());
> LOGGER.debug("with init"); // Should be logged
> // Second try to load configuration
> // From log4j FAQ : 
> https://logging.apache.org/log4j/2.x/faq.html#reconfig_from_code
> final LoggerContext context = (LoggerContext) LogManager.getContext(false);
> context.setConfigLocation(log4jConfiguration.toUri());
> LOGGER.debug("reconfig from code"); // Should be logged
> LOGGER.info("shutdown"); // Should be logged with [OUTER] prefix
> {code}
>  
> The code works when running from IDE, but when executed with {{java -jar}} 
> the external configuration is not loaded.
> Result when running from IDE:
> !image-2020-02-06-21-20-15-004.png!
> Result when running from jar:
> !image-2020-02-06-21-21-14-488.png!
>  
> I expect to have the configuration file loaded when running my jar file like 
> when running from IDE.
>  
> Edit: 
>  If I compile and execute the same code with java 8, the code works as 
> expected : 
>  !java 8.png! 
> So the issue seem specific to Java11.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to