[
https://issues.apache.org/jira/browse/LOG4J2-3081?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17327183#comment-17327183
]
Volkan Yazici commented on LOG4J2-3081:
---------------------------------------
Hey [~fprumbau]! Thanks for reaching out. Let me address your questions:
h1. Creating a fat JAR containing Log4j 2
As you have also hinted, it is cumbersome to create a fat JAR containing Log4j
2 due to the way the plugins are implemented. (I personally think creating fat
JARs is not a good idea, but that is another discussion.) Yet, it is still
possible! See if the following works for you:
{code:xml}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>.txt</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"
/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
<addHeader>false</addHeader>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"
/>
<transformer
implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer"
/>
</transformers>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.github.edwgiz</groupId>
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
<version>${maven-shade-plugin.log4j2-cachefile-transformer.version}</version>
</dependency>
</dependencies>
</plugin>
{code}
Note that this uses
[maven-shaded-log4j-transformer|https://github.com/edwgiz/maven-shaded-log4j-transformer].
h1. Loading {{JsonTemplateLayout}} programmatically in a fat JAR
{{JsonTemplateLayout}} uses {{@PluginBuilderAttribute}}:
{code:java}
@PluginBuilderFactory
public static Builder newBuilder() {
return new Builder();
}
{code}
Hence, AFAIC, it should work with {{PluginManager}}. Maybe [~mattsicker] or
[~ralphgoers] can explain what is missing?
> No factory method found for class
> org.apache.logging.log4j.layout.template.json.JsonTemplateLayout
> --------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-3081
> URL: https://issues.apache.org/jira/browse/LOG4J2-3081
> Project: Log4j 2
> Issue Type: Bug
> Components: JsonTemplateLayout
> Affects Versions: 2.14.1
> Reporter: Frank Prumbaum
> Priority: Major
>
> We are using log4j2 in an uber-jar, so plugin initialization via
> *Log4j2Plugins.dat* is not possible.
> Using a programmatic Approach with
> {color:#000000}PluginManager{color}.addPackage({color:#067d17}"org.apache.logging.log4j.layout.template.json"{color});
> we are getting the error
> java.lang.IllegalStateException: No factory method found for class
> org.apache.logging.log4j.layout.template.json.JsonTemplateLayout
> at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:234)
> at
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:134)
> Logging at the source code, a Method with @PluginFactory-annotation is
> missing.
> {color:#9e880d}@PluginFactory
> {color}{color:#0033b3}public static JsonTemplateLayout{color}
> {color:#00627a}createLayout(…){color}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)