log4j collision with multiple ejb containers - maven-2

I have implemented several Java applications stored in EJB containers which I deploy on the same Glassfish domain. Each of them has it's own log4j.properties file located in the resources folder of each's application project (they are all Maven projects).
A different log file is configured in each log4j.properties file but when I deploy my applications they end up to write in the same log file.
Does anyone know how to resolve this problem? :)
EDIT: Here are my log4j.properties files for two projects.
The first:
log4j.rootLogger=ALL,AppFileAppender
log4j.appender.AppFileAppender=org.apache.log4j.FileAppender
log4j.appender.AppFileAppender.File=${com.sun.aas.instanceRoot}/logs/Engine.log
log4j.appender.AppFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.AppFileAppender.layout.ConversionPattern= %d [%t] %-5p %c - %m%n
log4j.logger.hesemulatorproducer=ALL,AppFileAppender
log4j.logger.org.hibernate=info
The second:
log4j.rootLogger=ALL,AppFileAppender
log4j.appender.AppFileAppender=org.apache.log4j.FileAppender
log4j.appender.AppFileAppender.File=${com.sun.aas.instanceRoot}/logs/SendEndDeviceEvents.log
log4j.appender.AppFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.AppFileAppender.layout.ConversionPattern= %d [%t] %-5p %c - %m%n
log4j.logger.hesemulatorproducer=ALL,AppFileAppender

I cannot see comment link for this question. So I am asking few clarifications in this answer. These may help in finding root cause of the issue.
Can you please check the config file path and name, you specify while initializing Log4j?
Also, can you please give the file in which log is being printed for both projects? Is it server log or one of the application log file?
Are these projects being deployed in different WARs/EARs?
You can print repository location using org.apache.log4j.LogManager.getLoggerRepository().

Related

Weblogic server - Getting NoClassDeffError for TIFFImageReader even when the library is in classpath

I am working on TIFF to JPEG conversion program. I am using the TIFF implementation from jai-imageio-core.1.3.1.jar, which is available in the classpath.
Everything works fine in my local environment in eclipse (running on tomcat server). However, when I deploy the same in Weblogic, I am getting the following error. Weblogic server is unable to recognize the TIFF implementation classes. I am unable to find the missing link. Please help.
java.lang.NoClassDefFoundError: com/github/jaiimageio/impl/plugins/tiff/TIFFImageReader
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReaderSpi.createReaderInstance(TIFFImageReaderSpi.java:118)
at javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at javax.imageio.ImageIO.read(ImageIO.java:1443)
at javax.imageio.ImageIO.read(ImageIO.java:1308)
I will answer my own question. The issue is resolved. The problem was with the the jai-imageio-core.1.3.1.jar file present in multiple places. It was present in my application war file in WEB-INF/lib folder. however, the same jar file was also present outside the war in the weblogic adm root directory. (my bad)
I guess weblogic clearly expects the jar file only in 1 place (especially java SPI implementation jar)
It is also a good idea to search all directories under weblogic to make sure there are no additional jar files of the same name.
I had only one jai-imageio-core.1.3.1.jar file (in WAR file) and caught this error. Weblogic managed server restart helped me.

Log4J Application Specific Configuration file in Weblogic

My setup includes a weblogic 12c server which hosts several applications. The application which i am writing has log4j configuration property with appenders that are specific to this application. I have packaged the property in app EAR and deployed it to weblogic.
I want the log4j setup in weblogic to pull configuration from this property file. Will i still need a global configuration file put in inside the domain root folder? . The thing that confuses me is, why do i need to have log4j configuration in domain root if i already have it inside the application ( while i load using PropertyConfigurator) .
I did copy the log4j and wllog jars to domain/lib but i am not happy with copying anything to server directories since i want this to be driven by the deployed EAR.
I am new to Weblogic so might be something obvious. Tried several links on the web but none of them answers my question. I have been referring to this thread for the setup. https://community.oracle.com/thread/1063248
Make sure log4j jar is in APP-INF/lib
Make sure your log4j config file is in the root classpath for the ear (APP-INF/classes)
If you don't have one already, add a weblogic-application.xml (see http://docs.oracle.com/cd/E24329_01/web.1211/e24368/app_xml.htm#WLPRG389) to your META-INF directory at the EAR level, and in there include a prefer-application-packages element with package-name of org.apache.log4j

How to make a war file auto deploy?

How do you make a war file auto deploy?
The server component is glassfish and the database is created in MySQL. Do I need to create an executable file that will extract the war file? and how to do it so?
It should be sufficient to copy/move your WAR file to the following folder:
$GLASSFISH_HOME/glassfish/domains/domain1/autodeploy
(You may change the domain name if you are using a different one.)
See also:
How to to autodeploy war file with GlassFish
WAR doesn't get redeployed in Glassfish from autodeploy
Oracle GlassFish Server 3.0.1 Quick Start Guide - Deploying and Undeploying Applications

What are the pom.xml and log4j.properties under Apache CXF for?

I am new to Webservices and I need to know what the pom.xml and log4j.properties files are for in an Apache CXF project. I read the POM is used to represent a Maven project so it holds configuration files, dependencies etc. Is that correct? Why would I use Maven bulid instead ob sinpl runnig it as a Java application. And what is the .properties file for?
Thanks for any help.
You are correct about the POM file. It is a "Project Object Model" that holds the configuration files, dependencies. I use it because you can do a mvn clean install, instead of doing it separately, it splits the code into modules, dependency-relationships and versions.
log4j.properties is an open source API that is used to specify where you want your logs to be redirected. For example:
log4j.rootLogger=INFO, stdout
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
will make all your logs be output in the console.
If you want it to be saved in a file, use:
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
pom.xml is used to build (ex. create .jar files) the project using Maven. It it not used at runtime.
log4j.properties is a runtime configuration, that defines what logging information should be written and where. Check out these examples: http://www.mkyong.com/logging/log4j-log4j-properties-examples/

How does Intellij deploy to JBoss?

I finally have my application in IntelliJ and deploying to JBoss. I'd like to get hot deploy working but it looks like I need to understand how IntelliJ and JBoss interact.
When I build my project in IntelliJ and then start JBoss, the ear file does not appear in the deploy directory so I assume that there is some magic that IntelliJ does so that JBoss reads from a different folder. What is happening during this step?
Thanks :)
I know this is an old and apparently answered question, but unfortunately the links provided in the accepted answer didn't give me the simple details I was looking for. For anyone also trying to understand how IntelliJ IDEA deploys your exploded war to JBoss without copying files to the deployments folder, here's what I've found while deploying locally from IDEA 14 (EAP) to JBoss 7.1.1.Final:
After you've created an "exploded war" artifact for your project (or it has automatically been created for you), IDEA will build your provided sources and place the output in the directory set in the artifact options (you can change this setting to place the output inside the deployments folder inside your jboss installation).
IDEA will update your JBoss configuration file (/standalone/configuration/standalone.xml) and add a "deployment" node inside the deployments section. This entry simply defines a name, a runtime name and the exploded war root folder for your project, which will point to the output directory of your artifact set in IDEA.
When JBoss is started (either manually or from your run/debug configuration in IDEA), it will automatically deploy your artifact. Be warned that if your files are in the output directory of your project and you clean it, JBoss will still try to find the directory, thus encountering errors in your next attempt to start it: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to mount deployment content, Failed to process phase STRUCTURE of deployment and java.io.FileNotFoundException to name a few.
Please refer to the documentation.
Basically, you need an exploded Artifact configuration with the directory name ending with .ear.
Build | Make performs hot deployment as well as Update action (which is configurable and can update only resources, resources and classes, optionally redeploy or restart the server).
Instead of copying your application to JBoss, IDEA runs it with appropriate parameters so that it uses Artifact directory instead. Configuration is very flexible and you can just change the artifact directory location to reside under JBoss directory.