log4j2 JsonTemplateLayout not working with maven shade plugin - log4j2

i am trying to generate logs in Json format for that using log4j2 JsonTemplateLayout with LogstashJsonEventLayoutV1.json as the template. When i run the code using intellij everything works as expected. But using java -jar command it fails with
Unable to locate plugin for type JsonTemplateLayout
Below are the logs from intellij and command line using java -jar
Logs using java -jar command
2021-04-20 19:02:55,123 main DEBUG null null initializing configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration#6f45df59
2021-04-20 19:02:55,140 main DEBUG Installed 1 script engine
Warning: Nashorn engine is planned to be removed from a future JDK release
2021-04-20 19:02:55,723 main DEBUG Oracle Nashorn version: 11.0.10, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Na
shorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2021-04-20 19:02:55,723 main DEBUG PluginManager 'Core' found 122 plugins
2021-04-20 19:02:55,723 main DEBUG PluginManager 'Level' found 0 plugins
2021-04-20 19:02:55,739 main ERROR Unable to locate plugin type for JsonTemplateLayout
Logs when executing from Intellij
2021-04-20 18:52:50,289 main DEBUG Apache Log4j Core 2.14.1 initializing configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration#6ff29830
2021-04-20 18:52:50,306 main DEBUG Installed 1 script engine
Warning: Nashorn engine is planned to be removed from a future JDK release
2021-04-20 18:52:51,122 main DEBUG Oracle Nashorn version: 11.0.10, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2021-04-20 18:52:51,124 main DEBUG PluginManager 'Core' found 124 plugins
2021-04-20 18:52:51,124 main DEBUG PluginManager 'Level' found 0 plugins
2021-04-20 18:52:51,137 main DEBUG Building Plugin[name=property, class=org.apache.logging.log4j.core.config.Property].
Can anyone please help me resolve this issue?
Many thanks

below link helped to resolve this issue
https://github.com/edwgiz/maven-shaded-log4j-transformer

Related

Plugins in a Multiproject fails at Grails 3.2.11

Configuration
Following the Plugins and Multi-Project Builds section at the Grails 3.2.11 manual, its suppose that I can setup a Multi-project with the next commands in a terminal:
echo "Creating the root folder..."
mkdir test-multi-project
cd test-multi-project
echo "Creating the settings.gradle file..."
echo "include 'myapp', 'myplugin'" >> settings.gradle
echo "Creating the Grails application..."
grails create-app myapp
echo "Creating the Grails plugin..."
grails create-plugin myplugin
echo "Configuring the dependency between the application and the plugin..."
echo "grails { plugins { compile project(':myplugin') } }" >> myapp/build.gradle
echo "Executing the Grails application..."
cd myapp
grails run-app
Error
However, when I tried those commands for create and configure the Grails Application and the Plugin the grails run-app command throws next error:
FAILURE: Build failed with an exception.
* Where:
Build file '~/test-multi-project/myapp/build.gradle' line: 61
* What went wrong:
A problem occurred evaluating root project 'myapp'.
> Project with path ':myplugin' could not be found in root project 'myapp'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
CONFIGURE FAILED
Total time: 4.835 secs
| Error Error initializing classpath: Project with path ':myplugin' could not be found in root project 'myapp'. (Use --stacktrace to see the full trace)
Additional Information
I already tested the above commands using Grails 3.2.8, 3.2.9, 3.2.10 and 3.2.11 and the code throws the same error.
On the other hand, I tested the above commands using Grails 3.2.3, 3.2.5, and 3.2.7 and the project is executed fine. Also, the Grails landing page shows that 'mypluin' is been used by the application.
Note, I am using sdk to handle the Grails versions. The commands were executed using Java 1.7 and Yosemite:
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_141 (Azul Systems, Inc. 24.141-b11)
OS: Mac OS X 10.10.5 x86_64
Question:
I am wondering what else I need to do or what I am doing wrong in order to make this code works on Grails 3.2.11
Thanks in advance.
Jeff Brown fixed the above issue removing the multi-project-test2/myapp/settings.gradle file and adding the next line to the multi-project-test2/settings.gradle file:
project(':myapp').name = 'myapp'
As you can see at the next GitHub's commit: https://github.com/esalomon/multi-project-test2/commit/d92c3fbc67156bcd1af9f47dc6f2984534154bad
After the above updated the multi-project-test2 can be downloaded and it will work fine.
It is likely to have gone wrong at around this point:
echo "grails { plugins { compile project(':myplugin') } }" >> myapp/build.gradle
That segment needs to be added to existing block of that file not a new block (not that I have tested)
What happens when you follow the steps manually ? does it work that way and if so have you thought of doing a diff across files that changes to see what is different.
You are providing the script which is great and maybe someone else wishes to run through it but i suspect it is what has already been pointed out.
You should look into ed Something like this example:
I am using a grails 3.2.8 app which in the dependency segment ends like this:
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
Now if I execute
test328$ ed -s build.gradle <<EOF >/dev/null
g/^ testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
a
compile project(':myplugin')
.
w
q
EOF
you can now see:
tail -n20 build.gradle
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
compile project(':myplugin')
}
The new entry added on. You will need to find a pointer in your existing file generated by grails and use like above that pointer to add your entry
The ed script was used to demo this since obviously it wasn't clear enough previously

Grails 3.1.10 exclude spring-boot-starter-tomcat plugin from war generation

If I leave the "spring-boot-starter-tomcat" plugin dependency set to compile in the gradle build file I get the following error messages deploying to a standalone Tomcat 7 server:
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-core-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Aug 18, 2016 2:51:19 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-el-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
If I change the dependency to provided I can deploy to Tomcat but get the following error attempting to run or debug within IntelliJ IDEA 15:
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [orderserver.Application]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
...
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
How can I exclude these dependencies from the war file generation while retaining the ability to run/debug within IDEA?
Even better is there a way to generate a single war file that has embedded Tomcat for standalone execution that can also be deployed to a Tomcat container?
This issue was resolved by changing the dependency to provided and using a "Grails" run/debug configuration instead of the "Application" configuration that was set when I created the project with IDEA 15.

Getting error in GGTS for create a new project for Grails

When I am trying to create a new Grails project getting the following error:
Grails: 3.0.9
Jdk: 1.8
Command terminated with an exception: java.lang.Exception (see details for partial output)
Command: C:\Program Files\Java\jdk1.8.0_65\bin\javaw.exe (11-Nov-2015 11:43:39 am)
---- System.out ----
---- System.err ----
Error: Could not find or load main class org.codehaus.groovy.grails.cli.support.GrailsStarter
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
------System.out:-----------
------System.err:-----------
Error: Could not find or load main class org.codehaus.groovy.grails.cli.support.GrailsStarter
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Please help me to get the solution for this.
Thanks
It seems you are running the project (or create) as a Java project instead of Grails project, cause it is trying to execute de Main java class

Grails: Cobertura XML report missing on Sonar

I'm working on a web application using Grails 2.1.1 and it was requested me to make evidence about the test code coverage.
The project is using:
Maven 3.0.5
code-coverage 1.2.7 (grails plugin for Cobertura)
sonar-maven-plugin 2.5
SonarQube 3.7.4 (running on localhost)
On my pom.xml, there are declared the following sonar's properties:
<sonar.language>grvy</sonar.language>
<sonar.groovy.cobertura.reportPath>target/test-reports/cobertura/coverage.xml</sonar.groovy.cobertura.reportPath>
I successfully generate cobertura.xml report inside directory target/test-reports/cobertura, launching the command:
grails tA -coverage -xml
but when I run:
mvn sonar:sonar
It isn't displayed any test report on Sonar, although I receive as command response the following output lines:
[INFO] [15:20:42.007] Sensor Groovy CoberturaSensor...
[INFO] [15:20:42.007] Analyzing Cobertura report: target/test-reports/cobertura/coverage.xml
[INFO] [15:20:42.086] Sensor Groovy CoberturaSensor done: 79 ms

forked execution breaks includeTargets in Grails _Events.groovy plugin

seem to have more stupid issues with forked Execution in grails than anything else
using grails 2.4.4 on GGTS 3.6.3, groovy 2.3.7, 64bit
trying to repair another plugin (its out of date and i'm trying to fixit). had problems. pared all back to a simple plugin and demo project that includes the plugin from the local workspace
in DemoProject I do the local include of the plugin like this in buildConfig.groovy
grails.plugin.location.DummyPlugin = "../DummyPlugin"
so far so good. without adding an _Events.grooy and running the DemoProject all starts ok and plugin loads.
now add an _Events.groovy to the plugins /script folder. In that file I have this line right at top
import grails.util.BuildSettingsHolder as build
import groovy.xml.MarkupBuilder
includeTargets << grailsScript("_GrailsPackage")
now when you run the demo project you get an error like this
|Running Grails application
Error |
Error loading event script from file [E:\workspace\ggts3.6.2-workspace\DummyPlugin\scripts\_Events.groovy] No such property: classLoader for class: java.lang.Object (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
groovy.lang.MissingPropertyException: No such property: classLoader for class: java.lang.Object
at grails.util.BuildSettings$1.doCall(BuildSettings.groovy:409)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at _Events.run(_Events.groovy:29)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.createEventListener(ForkedTomcatServer.groovy:147)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.createTomcatRunner(ForkedTomcatServer.groovy:104)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.runInternal(ForkedTomcatServer.groovy:82)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.run(ForkedTomcatServer.groovy:66)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer$run.call(Unknown Source)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.main(ForkedTomcatServer.groovy:60)
Error |
Error loading event script from file [E:\workspace\ggts3.6.2-workspace\DummyPlugin\scripts\_Events.groovy] No such property: classLoader for class: java.lang.Object
|Server running. Browse to http://localhost:8080/DemoDummyProject
if you got back to the DemoProject and stopped forked Execection by setting grails.project.fork =[] and run again it all works fine - no errors.
so essentially forked execution screws up the plugins includeTargets action.
how do you fix this whilst std forked config is now enabled as default - any clues? advice requested

Resources