I have problem when export to executable jar.
I'm using maven and slf4j with log4j
My pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
I added a log4j.xml in /src/java/main (is the same that in generated target folder):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/media/dlm/log/dlm.log" />
<param name="Threshold" value="INFO" />
<param name="Append" value="false" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="1" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m %n" />
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m %n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
But when I export from eclipse the log4j.xml is changed for the next one:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/tmp/dlm/log4j.log" />
<param name="Threshold" value="INFO" />
<param name="Append" value="false" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="1" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %X{service} %X{user} [%c] %m%n" />
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="ERROR" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %X{service} %X{user} [%c{1}] %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="CONSOLE" />
</root>
</log4j:configuration>
I tried using log4j.properties file as appear here, but nothing.
Thanks in advance your answers.
Thanks to Peter I understood that when run an aplicacition with eclipse I was using eclipse options and not maven itself to build my app. That was the reason log4j.xml probably change. The next solution not resolve why it happens, but resolve the problem and give me a correct way to build my app using 100% maven.
I just need to add some new fields to my pom.xml to make things that eclipse options probably add automatically.
1.-Include xml files:
<build>
...
<!-- RECURSOS -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>log4j.xml</include>
</includes>
</resource>
</resources>
...
</build>
2.- Executable jar (I have 3 different main classes in same project):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>${class.main}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
3.- Add profiles to select main class:
<profiles>
<!-- DLM ANALOG -->
<profile>
<id>dlmdesktopanalog</id>
<properties>
<class.main>cl.icpdas.dlm.desktop.fx.main.analog.DataLoggerAnalogManager</class.main>
</properties>
</profile>
<!-- DLM DIGITAL -->
<profile>
<id>dlmdesktopdigital</id>
<properties>
<class.main>cl.icpdas.dlm.desktop.fx.main.digital.DataLoggerDigitalManager</class.main>
</properties>
</profile>
<!-- DLM EXTRACTOR -->
<profile>
<id>dlmdesktopextractor</id>
<properties>
<class.main>cl.icpdas.dlm.desktop.fx.main.extractor.DataLoggerExtractorManager</class.main>
</properties>
</profile>
</profiles>
Finally, I used the next goals make my executable jar.
mvn clean package assembly:single -e -P dlmdesktopanalog
Anyway, if someone knows where eclipse set log4j.xml and other options when make a exejutable jar or what is reasson why it changes log4j.xml the answers are wellcome as comment.
Related
I have the following config file
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Demo" value="true"/>
<setting name="Demo2" value="true"/>
</settings>
</sitecore>
</configuration>
And I want it transformed into this
<configuration xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore role:require="Standalone OR ContentDelivery OR ContentManagement">
<settings>
<setting name="Demo" value="false"/>
<setting name="Demo2" value="true"/>
</settings>
</sitecore>
</configuration>
I have tried to use this https://fatantelopetester.apphb.com/ and obtained the following transformation config file:
<?xml version="1.0" encoding="utf-16"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xdt:Transform="SetAttributes(xmlns:role,xmlns:set)" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<sitecore role:require="Standalone OR ContentDelivery OR ContentManagement" xdt:Transform="SetAttributes(role:require)">
<settings>
<setting name="Demo" xdt:Locator="Match(name)" value="false" xdt:Transform="SetAttributes(value)" />
</settings>
</sitecore>
</configuration>
But apparently this transformation is not good enough and not working.
Any ideas how to make it work, in conditions when under
<sitecore>
I have lots of other setting? (Here I've added just a sample)
I just ran into a similar issue myself and found a solution that worked for me. I'm not using SlowCheetah but I am using a tool that uses XDT under the hood.
The XDT would fail around xdt:Transform="SetAttributes(role:require)" because the namespace wasn't found. However, using xdt:Transform="SetAttributes" didn't seem to have the same problem and was able to set the attribute just fine.
I have downloaded the newest version of Quartz.Net and try to configure it with common.logging and log4net dlls by using below configuration (based on this example)
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=2.1.2.400,Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4" />
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="MyQuartzLog.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
<quartz>
<add key="quartz.scheduler.instanceName" value="QuartzTestLog4Net" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="2" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
</quartz>
It does not work.
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=2.1.2.400,Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4" />
results in component loading error. I used sn.exe to check the publickeytoken. The keytoken is correct.
Removing the quartz sction can make the application run. But the log object has NoOpLogger information - {Common.Logging.Simple.NoOpLogger}.
My project refers to Common.Logging version 2.1.2.0; Common.Logging.Log4Net version 2.0.0.0; and log4net version 1.2.10.0. Are they right versions? If not, what are the right ones.
Thanks,
You should check the sample server that comes with Quartz.NET distribution.
https://github.com/quartznet/quartznet/tree/master/server/Quartz.Server
App.config:
It's type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
NameValueSectionHandler is BCL type, not Quartz.NET's
You can probably leave out the version and public key
Package.config
You might have wrong packages. packages.config in sample contains working combination when using Log4Net 1.2.11
I want to deploy my web application on JBOSS6. The applicaation itself works, but the logging doens't. I use log4j and have added a jboss-deployment-structure.xml to my war. The contents are
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.logging" />
</exclusions>
</deployment>
In my log4j.xml I have
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="LogAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\web.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/>
</layout>
</appender>
<logger name="be.sofico.web">
<level value="debug" />
<appender-ref ref="LogAppender" />
</logger>
This all works fine on tomcat and websphere (when I set classloading parent last)
How can I get it to work on JBOSS 6?
I solved my problem doing the following:
put jboss-deployment-structure.xml inside web\META-INF with the following in the file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
</exclusions>
</deployment>
</jboss-deployment-structure>
And add this to the startup of the server: -Dorg.jboss.as.logging.per-deployment=false
to set my log4j in the classpath correctly i did 2 things :
1) I set the name of the log4j to use like this
-Dlog4j.configuration=fox-log4j.xml
this one has to be in the CLASSPATH
2) I call the logging manager explicitly otherwise the jboss log4j wont work
this gives in my run.conf :
#parameter used by the JVM and call later in the log4j.xml
LOG_FOLDER=$DIRNAME/../server/default/log
#jvm options
JAVA_OPTS="-Xms256m -Xmx4096m -XX:MaxPermSize=1024m -Dlog4j.configuration=fox-log4j.xml \
-Dfile.encoding=UTF-8 -Dfile.io.encoding=UTF-8 -DjavaEncoding=UTF-8 -Djboss.platform.mbeanserver \
-Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl \
-Djava.util.logging.manager=org.jboss.logmanager.LogManager \
-Dorg.jboss.logging.Logger.pluginClass=org.jboss.logging.logmanager.LoggerPluginImpl \
-DLOG_FOLDER=$LOG_FOLDER"
now a piece of my log4j :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="FOX_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="25MB"/>
<param name="MaxBackupIndex" value="5"/>
<param name="File" value="${LOG_FOLDER}/fox.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-15x %t %-5p %-50.50c{1} - %m%n"/>
</layout>
</appender>
<category name="com.mycompany" additivity="true">
<priority value="DEBUG"/>
<appender-ref ref="FOX_LOG"/>
</category>
<root>
<priority value="INFO"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
hope this could help.
regards
It means it is not loading your log4j.xml. Something wrong with the xml file location or issue with the class loader finding this log4j.xml.
I'm using the latest 5.x ReSharper plugin with NUnit 2.5.10. When using Log4Net to log some events for testing purposes the results show up in the ReSharper test window, but do not show up when using NUnit's console unit runner (run as part of our build processes). I've tried giving NUnit a .config file in the same location as the .nunit configuration file with the LogLevelThreshold set to DEBUG, but it still won't log the actual test information to either the output file or the text window in NUnit's GUI. I'm a bit stumped at this point, is there a way to get the two in sync in what's being displayed by test output? Thanks!
Configs in question:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestCaseBuilder" type="System.Configuration.NameValueSectionHandler"/>
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="DefaultLogThreshold" value="DEBUG" />
</TestRunner>
</NUnit>
</configuration>
And other config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
<!--<appender-ref ref="DebugAppender" />-->
</root>
<logger name="NHibernate">
<level value="INFO" />
</logger>
<logger name="NHibernate.SQL">
<level value="DEBUG" />
</logger>
</log4net>
</configuration>
Thanks in advance for any help.
I need to use XML to JSON lib in my war.
I followed a tutorial explaining that dependencies are required in the project.
But when I add the following in my ant build.xml (the file used to create the war), Eclipse complains about the artifact:dependencies, seems like it does not like the :.I have the following error message:
The prefix artifact for element artifact:dependencies is not bound...
<artifact:dependencies filesetId="dependency.fileset"
sourcesFilesetId="sources.dependency.fileset"
javadocFilesetId="javadoc.dependency.fileset"
versionsId="dependency.versions">
<!-- DEPENCIES GO HERE -->
</artifact:dependencies>
Any idea ?
UPDATE
I have the same problem trying to define an in-memory pom with:
<artifact:pom id="mypom" groupId="org.acme" artifactId="project1" version="1.0">
<dependency groupId="junit" artifactId="junit" version="4.1"/>
<dependency groupId="org.codehaus.plexus" artifactId="plexus-utils" version="1.5.5"/>
<license name="apache" url="http://www.apache.org"/>
</artifact:pom>
The prefix artifact for element artifact:pom is not bound...
UPDATE 2
I installed maven-ant jar in ant/lib and change the build.xml so it contains the definition of the artifact stuff but I have an error message while running it.
<project name="test" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<artifact:dependencies pathId="dependency.classpath">
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
...
The error message Eclipse gave is:
BUILD FAILED
D:\J2EE\workspace\Test\build.xml:3: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:dependencies
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
-C:\Documents and Settings\luc\.ant\lib
-a directory added on the command line with the -lib argument
The maven-ant jar does exist in -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
UPDATE 3
This is the build.xml file I'm using.
<!--
<project name="Monitoring" default="install" xmlns:artifact="urn:maven-artifact-ant" xmlns:test="urn:test-tasks">
-->
<project name="Monitoring" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- project-specific variables -->
<property environment="env" />
<property name="project_home" value="D:\J2EE\workspace\Monitoring"/>
<property name="webapp.dir" value="${project_home}/target" />
<property name="jboss.dir" value="D:\J2EE\jboss\standalone\deployments" />
<property name="package.name" value="monitoring.war" />
<property name="lib.dir" value="${project_home}/lib" />
<property name="src.dir" value="${project_home}/src" />
<property name="resources.dir" value="${project_home}/resources" />
<property name="dest.dir" value="${project_home}/target" />
<property name="package.file" value="${dest.dir}/${package.name}" />
<!-- put everything in a temp folder with the right structure during the build -->
<property name="temp.dir" value="${project_home}/temp" />
<property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" />
<path id="build.class.path">
<fileset dir="${env.JAVA_HOME}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="D:\ant\lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="deps">
<artifact:dependencies pathId="dependency.classpath">
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.1</version>
</dependency>
</artifact:dependencies>
</target>
<target name="clean" depends="deps">
<delete>
<fileset dir="${dest.dir}" includes="**/*"/>
</delete>
<delete dir="${temp.dir}" />
<delete dir="${temp.dir.classes}" />
<delete dir="${temp.dir.meta-inf}" />
<delete dir="${temp.dir.web-inf}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${dest.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${temp.dir.lib}" />
<mkdir dir="${temp.dir.meta-inf}" />
<mkdir dir="${temp.dir.web-inf}" />
<mkdir dir="${temp.dir.classes}" />
</target>
<!-- COMPILE -->
<target name="compile" depends="prepare">
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files ...</echo>
<javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}" includes="**/*" includeantruntime="false">
<classpath refid="build.class.path" />
<classpath refid="dependency.classpath" />
</javac>
</target>
<!-- PACKAGE -->
<target name="package" depends="compile">
<echo>=== PACKAGE ===</echo>
<!-- copy the config files -->
<copy file="${resources.dir}/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />
<copy file="${resources.dir}/manifest.mf" tofile="${temp.dir.meta-inf}/manifest.mf" overwrite="true" />
<copy todir="${temp.dir.classes}">
<fileset dir="${src.dir}">
<include name="**/*.xml"/>
<include name="**/*.xsl"/>
</fileset>
</copy>
<!-- the ant war task. with all resources in place, create the war file -->
<war destfile="${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">
<lib dir="${lib.dir}" />
<classes dir="${temp.dir.classes}" />
</war>
</target>
<!-- INSTALL -->
<target name="install" depends="package">
<echo>=== INSTALL ===</echo>
<copy file="${package.file}" tofile="${webapp.dir}/${package.name}" overwrite="true" />
<copy file="${package.file}" tofile="${jboss.dir}/${package.name}" overwrite="true" />
</target>
</project>
It was working well before I added all the dependencies stuff... still cannot find out the pb here. Any help would be very welcome.
It looks like you're making use of Maven Ant Tasks. To do this you'll need a copy of the jar from the download area here.
Once (or if) you've got that, you'll need to modify your buildfile to use it.
The main things that are needed are to define the artifact namespace, and add the typedef for the ant-lib:
<project name="foo" default="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
I had the same error message but the cause was different.
Going to Window -> Preferences -> Ant -> Runtime and setting Ant Home solved my problem.
So for anyone that above solution doesn't work, check if "Ant Home" is pointing to the right direction