Problems with logback - jsf

This thread solve my problem in WAR (JSF 2) project, but when project is EAR this solution dont work.
Logback and Jboss 7 - don't work together?
I am using JBOSS 7.1.
UPDATE:
I create a new JSF project in eclipse (JBoss Tools and JBOSS 7.1 runtime). Add the jars slf4j-api-1.7.5.jar, logback-core-1.0.13.jar, logback-classic-1.0.13.jar and logback-access-1.0.13.jar.
this code in bean:
#Named
public class BeanTeste {
private Logger log = LoggerFactory.getLogger(BeanTeste.class);
public void executar(){
log.debug("TESTE DE DEBUG");
log.info("TESTE DE INFO");
log.warn("TESTE DE WARN");
// print internal state
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
System.out.println("METODO COMPLETADO!");
}
should return:
18:00:09,278 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09.274 [http--0.0.0.0-8080-1] DEBUG com.br.teste.BeanTeste - TESTE DE DEBUG
18:00:09,280 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09.279 [http--0.0.0.0-8080-1] INFO com.br.teste.BeanTeste - TESTE DE INFO
18:00:09,282 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09.282 [http--0.0.0.0-8080-1] WARN com.br.teste.BeanTeste - TESTE DE WARN
18:00:09,284 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09,223 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
18:00:09,286 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09,224 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
18:00:09,288 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09,224 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
18:00:09,291 INFO [stdout] (http--0.0.0.0-8080-1) 18:00:09,225 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration.
18:00:09,293 INFO [stdout] (http--0.0.0.0-8080-1)
18:00:09,293 INFO [stdout] (http--0.0.0.0-8080-1) METODO COMPLETADO!
but return
Exception starting filter WicketFilter: java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to ch.qos.logback.classic.LoggerContext
in a WAR project, I create a jboss-deployment-structure.xml file and place it in WEB-INF directory and solved my problem.
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
</exclusions>
</deployment>
</jboss-deployment-structure>
When the WAR project is add a EAR project the problem returns.
any ideas?

I changed my jboss-deployment-structure.xml with the content below and it worked.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.ext" />
<module name="org.slf4j.impl" />
<module name="org.slf4j.jcl-over-slf4j" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.logging"/>
<module name="org.jboss.logging.jul-to-slf4j-stub"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.log4j.logmanager"/>
<module name="org.apache.log4j"/>
<module name="org.log4j"/>
</exclusions>
<dependencies>
</dependencies>
</deployment>
<sub-deployment name="Teste.war">
<exclusions>
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.ext" />
<module name="org.slf4j.impl" />
<module name="org.slf4j.jcl-over-slf4j" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.logging"/>
<module name="org.jboss.logging.jul-to-slf4j-stub"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.log4j.logmanager"/>
<module name="org.apache.log4j"/>
<module name="org.log4j"/>
</exclusions>
</sub-deployment>
<sub-deployment name="TesteEJB.jar">
<exclusions>
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.ext" />
<module name="org.slf4j.impl" />
<module name="org.slf4j.jcl-over-slf4j" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.logging"/>
<module name="org.jboss.logging.jul-to-slf4j-stub"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.log4j.logmanager"/>
<module name="org.apache.log4j"/>
<module name="org.log4j"/>
</exclusions>
</sub-deployment>
thanks a lot!!!!

Related

How to CheckStyle a specific string in a filetype

I am currently figuring out a way on how to add a CheckStyle for Cucumber's Feature file.
Tried searching but I couldn't find an answer.
Essentially what I want to accomplish is
Search for a tag/string called #develop for every .feature file.
If this tag is found, return the CheckStyle error.
As of now what I have is ( doesn't work ):
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="fileExtensions" value="feature"/>
<module name="RegexpSingleline">
<property name="format" value="#develop"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has a #develop tag."/>
</module>
</module>
When I tried :
<module name="Checker">
<module name="Regexp">
<property name="format" value="(#develop)"/>
</module>
</module>
IntelliJ stated I can't add RegEx under Checker.
Here's my POM for the CheckStyle plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<skip>${skipStaticAnalysis}</skip>
<consoleOutput>true</consoleOutput>
<configLocation>build_config/checkstyle.xml</configLocation>
<propertyExpansion>basedir=${project.basedir}</propertyExpansion>
<violationSeverity>info</violationSeverity>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
</sourceDirectories>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

server is not storing view state as the value of javax.faces.ViewState post migration to wildfly 10 from JBoss 6

We have migrated our application from JBoss 6 to Wildfly 10. After migration the server is not storing the view state as the value of javax.faces.ViewState hidden input field after the first http response.
Application logic is storing it on server end and the scenario is to validate input text field on click of submit button. After the first http response the hidden input field disappears and on submitting some text value again, the text value is deleted and bean.xml is not called.
There has been no change in the application end. However the only difference is: Jboss had web.xml deployed with servlet mapping provided in the application war and in case of wildfly user has to deploy the war of application with wildfly 10 independently installed on the machine.
Primefaces 3.4, JSF 2.2 and Mojarra 2.2.14 is used.
The modules.xml is as below:
Path: \modules\system\layers\base\com\sun\jsf-impl\main
<module xmlns="urn:jboss:module:1.3" name="com.sun.jsf-impl">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<dependencies>
<module name="javax.faces.api"/>
<module name="javaee.api"/>
<module name="javax.servlet.jstl.api"/>
<module name="org.apache.xerces" services="import"/>
<module name="org.apache.xalan" services="import"/>
<module name="org.jboss.weld.core"/>
<module name="org.jboss.weld.spi"/>
<module name="javax.xml.rpc.api"/>
<module name="javax.rmi.api"/>
<module name="org.omg.api"/>
</dependencies>
<resources>
<resource-root path="jsf-impl-2.2.14.jar"/>
</resources>
Path: \modules\system\layers\base\javax\faces\api\main
<module xmlns="urn:jboss:module:1.3" name="javax.faces.api" slot="2.2.14">
<dependencies>
<module name="com.sun.jsf-impl"/>
<module name="javax.enterprise.api" export="true"/>
<module name="javax.servlet.api" export="true"/>
<module name="javax.servlet.jsp.api" export="true"/>
<module name="javax.servlet.jstl.api" export="true"/>
<module name="javax.validation.api" export="true"/>
<module name="org.glassfish.javax.el" export="true"/>
<module name="javax.api"/>
</dependencies>
<resources>
<resource-root path="jsf-api-2.2.14.jar"/>
</resources>
</module>
What is being missed here?

Deploying JSF 1.2 based web application to JBoss EAP 7.0

I have a web application which is based on JSF 1.2 . The JSF jars are packed in the WAR library. We we try to deploy the war in JBoss EAP 7.0 , the war gets deployed successfully but the application does not run.
I found that JBoss EAP 7.0 does not support JSF 1.2 . My web application is not JSF 2.0 complaint. It will be great help if some body can list down steps to do so.
Thanks
Please try these steps:
Add a deployment-structure.xml to your project (WEB-INF/jboss-deployment-structure.xml to the WAR or META-INF/jboss-deployment-structure.xml to the EAR) with the exclusions:
<exclusions>
<module name="javax.faces.api" slot="main" />
<module name="com.sun.jsf-impl" slot="main" />
<module name="org.jboss.as.jsf-injection" slot="main" />
</exclusions>
Import all dependecies in pom.xml, what jsf need. Like that:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2-b19</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2-b19</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.11</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.0</version>
</dependency>
Actually this combination worked for me on EAP 7 version of JBOSS 7.1.5 servers.
This way I was able to load jsf1.2 jars from my WEB-INF/lib folder rather than what was supplied by JBOSS 7.1.5.
I had a EAR file which had the WAR file.
Web.xml:
<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>
In ear META-INF/jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<deployment>
<exclusions>
<module name="javax.faces.api" slot="main" />
<module name="com.sun.jsf-impl" slot="main" />
</exclusions>
</deployment>
<sub-deployment name="yourwarfilename.war">
<exclusions>
<module name="javax.faces.api" slot="main" />
<module name="com.sun.jsf-impl" slot="main" />
</exclusions>
</sub-deployment>
</jboss-deployment-structure>

Log4j not working

I using common logging and jboss eap 6.2 in java application, log file is creating but empty and hibernate log also not working.
This is my jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.commons.logging"/>
<module name="org.apache.log4j"/>
</exclusions>
</deployment>
<sub-deployment name="abc.war">
<exclusions>
<module name="org.apache.log4j"/>
<module name="org.apache.commons.logging"/>
</exclusions>
</sub-deployment>
</jboss-deployment-structure>
and this is my log4j.properties
log4j.rootLogger=DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=c\:\\log\\eSocietySQLLog.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxBackupIndex=5
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c %n%m%C
log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a
and add JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false" in standalone.conf of jboss eap 6.2.
I got the answer, my log4j is working.
1) I create the module in my jboss eap 6.2 GA jboss_home/modules/com
module is log4j/mylog4j/main
in main folder putted the module.xml file and log4j-1.2.16.jar
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.fourthdti.esociety">
<resources>
<resource-root path="log4j-1.2.16.jar"/>
</resources>
<dependencies>
<module name="org.apache.log4j"/>
<module name="javax.api"/>
</dependencies>
</module>
2) Add the single line code at end file standalone.conf which is in JBOSS_HOME/bin
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"
3) Create the jboss-deployment-structure.xml in my META_INF of ear
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment name="eSociety-ear.ear">
<dependencies>
<module name="com.log4j.mylog4j" export="true" />
</dependencies>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.jboss.logging" />
<module name="org.antlr"/>
<module name="org.hibernate.*"/>
</exclusions>
</deployment>
<sub-deployment name="abc-ejb-0.0.1-SNAPSHOT.jar">
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.jboss.logging" />
<module name="org.antlr"/>
<module name="org.hibernate.*"/>
</exclusions>
</sub-deployment>
<sub-deployment name="abc-web-0.0.1-SNAPSHOT.war">
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.jboss.logging" />
<module name="org.antlr"/>
<module name="org.hibernate.*"/>
</exclusions>
</sub-deployment>
</jboss-deployment-structure>
4) Putted log4j.properties in my class path
log4j.rootLogger=DEBUG, FILE, stdout
log4j.logger.org.hibernate=debug
log4j.logger.org.springframework=debug
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.SQL=trace
log4j.logger.org.hibernate.type= trace
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
#log4j.logger.org.hibernate.jdbc=trace
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=c\:\\log\\eSociety.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c - %m%n
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxBackupIndex=2
5) Add dependencies in pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
It is enough for my log4j configuration.

How to configure log4j using Netbeans and Maven for standalone app

Setting up a new standalone app and want to use log4j. Am using Maven on Netbeans (6.5), and was able to add the log4j jar/dependency, but it can't seem to find my log4j.xml file and I'm not sure how to tell Netbeans to find it.
Here's my error:
log4j:WARN No appenders could be found for logger (com.domain.project).
log4j:WARN Please initialize the log4j system properly.
log4j.xml path is src/main/resources/com/domain/product/gui/resource/log4j.xml
Note: the location of the log4j.xml was chosen to be consistent with legacy code (i.e. so future maintainers can find it), but this could be changed if necessary.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.domain.project</groupId>
<artifactId>project-log</artifactId>
<packaging>jar</packaging>
<version>0.1-SNAPSHOT</version>
<name>project-log</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Here's my very simple log4j.xml:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<category name="com.domain.project">
<priority value="debug"/>
</category>
<root>
<priority value="info"/>
<appender-ref ref="ConsoleAppender"/>
</root>
</log4j:configuration>
And my call to set up logging:
static Logger log = Logger.getLogger("com.domain.project");
How do I tell Netbeans to set up a Maven classpath to this configuration file?
Ilane
I recently faced the same problem when I wanted to get the logging working when the application was launched from within the IDE.
My solution is to use the additionalArguments of the nbm-maven-plugin as illustrated below.
Notice the use of -J-Dlog4j.configuration=... the extra -J ensures that the option is passed to the application, otherwise it only affects the JVM of the maven launcher.
<build>
<pluginManagement
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<brandingToken>${brandingToken}</brandingToken>
<cluster>${brandingToken}</cluster>
<additionalArguments>-J-Dlog4j.configuration=file:${basedir}/log4j.properties</additionalArguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Location of log4j.xml is rather strange. I would place it in src/main/resources and the problem would disappear. If you need some legacy tools to find the same file where they need it, try to copy it there in generate-resources phase. For example, with maven-antrun-plugin

Resources