Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/util/Tool - hadoop

I get below error when i package (jar) and run my defaulthadoopjob.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/util/Tool
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.Tool
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 12 more
Could not find the main class: DefaultHadoopJobDriver. Program will exit.
Commands used to build Jar.
# jar -cvf dhj.jar
# hadoop -jar dhj.jar DefaultHadoopJobDriver
The above command gave me error "Failed to load Main-Class manifest attribute from dhj.jar"
rebuilt jar with manifest using below command
jar -cvfe dhj.jar DefaultHadoopJobDriver .
hadoop -jar dhj.jar DefaultHadoopJobDriver -- This returned the original error message that I reported above.
My Hadoop job has single class "DefaultHoopJobDrive" that extends Configures and implements Tool, and run method as only code for Job creation and inputpath,outpurpath set.
Aslo I.m using new API.
I'm running hadoop 1.2.1 and the Job works fine from eclipse.
This might be something to do with the classpath. Please help.

For executing that jar you don't have to give hadoop -jar. The command is like so:
hadoop jar <jar> [mainClass] args...
If this jar again gets the java.lang.ClassNotFoundException exception then can you use the:
hadoop classpath
command to see whether hadoop-core-1.2.1.jar is present in your hadoop installations classpath?
FYI, and if it's not present in this list you have to add this jar to the hadoop lib directory.

Try building your hadoop java code with all hadoop jars available in hadoop's lib folder.
In this case you are missing the hadoop util class which is present in the hadoop-core-*.jar
Classpath can be specified while building the code within the jar or you can externalise it using the following command
hadoop -cp <path_containing_hadoop_jars> -jar <jar_name>

In case anyone is using Maven and lands here: Dependency issues can be resolved by asking Maven to include any jars it requires within the parent project's jar itself. That way, Hadoop doesn't have to look elsewhere for dependencies -- it can find them right there itself. Here's how to do this:
1. Go to pom.xml
Add a section to your <project> tag, called <build>
Add the following to your <build></build> section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.slf4j:slf4j-api</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:jmock</exclude>
<exclude>xml-apis:xml-apis</exclude>
<exclude>org.testng:testng</exclude>
<exclude>org.mortbay.jetty:jetty</exclude>
<exclude>org.mortbay.jetty:jetty-util</exclude>
<exclude>org.mortbay.jetty:servlet-api-2.5</exclude>
<exclude>tomcat:jasper-runtime</exclude>
<exclude>tomcat:jasper-compiler</exclude>
<exclude>org.apache.hadoop:hadoop-core</exclude>
<exclude>org.apache.mahout:mahout-math</exclude>
<exclude>commons-logging:commons-logging</exclude>
<exclude>org.mortbay.jetty:jsp-api-2.1</exclude>
<exclude>org.mortbay.jetty:jsp-2.1</exclude>
<exclude>org.eclipse.jdt:core</exclude>
<exclude>ant:ant</exclude>
<exclude>org.apache.hadoop:avro</exclude>
<exclude>jline:jline</exclude>
<exclude>log4j:log4j</exclude>
<exclude>org.yaml:snakeyaml</exclude>
<exclude>javax.ws.rs:jsr311-api</exclude>
<exclude>org.slf4j:jcl-over-slf4j</exclude>
<exclude>javax.servlet:servlet-api</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/jruby.home</exclude>
<exclude>META-INF/license</exclude>
<exclude>META-INF/maven</exclude>
<exclude>META-INF/services</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Now build your project again, and run with the normal hadoop java my.jar ... command. It shouldn't cry about dependencies now. Hope this helps!

Related

How can I run JDK 19 with Structured Concurrency? (ERROR: java.lang.NoClassDefFoundError: jdk/incubator/concurrent/StructuredTaskScope)

Note: this post somehow related with this question; however, the error is different. So I am posting as another question.
I want to try the new Project Loom feature defined in: JEP 428: Structured Concurrency (Incubator)
I created a library project that uses class StructuredTaskScope, which can compile right.
Then I created a test project to demonstrate the use of library project, which can compile right too.
In pom.xml, both projects use:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>19</release>
<compilerArgs>
<arg>--enable-preview</arg>
<arg>--add-modules=jdk.incubator.concurrent</arg>
</compilerArgs>
</configuration>
</plugin>
However, When i try to run the test project, it returns error below:
C:\me\codes\com.tugalsan\tst\com.tugalsan.tst.thread>java -jar target/com.tugalsan.tst.thread-1.0-SNAPSHOT-jar-with-dependencies.jar --enable-preview --add-modules jdk.incubator.concurrent
Exception in thread "main" java.lang.NoClassDefFoundError: jdk/incubator/concurrent/StructuredTaskScope
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at com.tugalsan.api.thread.server.TS_ThreadFetchAll.<init>(TS_ThreadFetchAll.java:44)
at com.tugalsan.api.thread.server.TS_ThreadFetchAll.of(TS_ThreadFetchAll.java:85)
at com.tugalsan.tst.thread.Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: jdk.incubator.concurrent.StructuredTaskScope
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 12 more
I also tried adding '=' character, but no luck: java -jar target/com.tugalsan.tst.thread-1.0-SNAPSHOT-jar-with-dependencies.jar --enable-preview --add-modules=jdk.incubator.concurrent
As Joachim Sauer answered:
Everything after the -jar filename.jar will be passed as an argument.
Hence to run an app with jdk.incubator.concurrent, one should use below order:
java --enable-preview --add-modules jdk.incubator.concurrent -jar JARFILENAME.jar argument0 argument1 argument2...

How to override spark jars while running spark-submit command in cluster mode? (okhttp3)

There is a conflict of jar in my project and jar in spark-2.4.0 jars folder. My Retrofit brings okhttp-3.13.1.jar (verified in mvn dependancy:tree) but spark in server has okhttp-3.8.1.jar, and I get NoSuchMethodException. So, I'm trying to give my jar explicitly to override it. When I try running spark submit command in client mode, it picks up the explicit jar that I have provided but when I try running the same in cluster mode, this fails to override the jar at the worker nodes, and executors use the same old jar of Spark which leads to NoSuchMethodError. My jar is a fat jar but spark jar somehow takes precedence over the same. If i can delete the jars provided by Spark, it would work probably but I can't as other services may be using it.
Following is my command:
./spark-submit --class com.myJob --conf spark.yarn.appMasterEnv.ENV=uat --conf spark.driver.memory=12g --conf spark.executor.memory=40g --conf spark.sql.warehouse.dir=/user/myuser/spark-warehouse --conf "spark.driver.extraClassPath=/home/test/okhttp-3.13.1.jar" --conf "spark.executor.extraClassPath=/home/test/okhttp-3.13.1.jar" --jars /home/test/okhttp-3.13.1.jar --conf spark.submit.deployMode=cluster --conf spark.yarn.archive=hdfs://namenode/frameworks/spark/spark-2.4.0-archives/spark-2.4.0-archive.zip --conf spark.master=yarn --conf spark.executor.cores=4 --queue public file:///home/mytest/myjar-SNAPSHOT.jar
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(configuration.ApiUrl()) //this throws nosuchmethodexception
.addConverterFactory(JacksonConverterFactory.create(new ObjectMapper()))
.build();
My mvn dependency:tree doesnt indicate any other transitive jars in my jar. And it runs fine in local in IntelliJ as well as with mvn clean install.
I even tried providing hdfs path of jars(hdfs://users/myuser/myjars/okhttp-3.13.1.jar) with no luck. Can someone throw some light ?
I get the following exception if I try both --conf "spark.driver.userClassPathFirst=true" --conf "spark.executor.userClassPathFirst=true"
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.spark.deploy.yarn.YarnSparkHadoopUtil$.<init>(YarnSparkHadoopUtil.scala:48)
at org.apache.spark.deploy.yarn.YarnSparkHadoopUtil$.<clinit>(YarnSparkHadoopUtil.scala)
at org.apache.spark.deploy.yarn.Client$$anonfun$1.apply$mcJ$sp(Client.scala:81)
at org.apache.spark.deploy.yarn.Client$$anonfun$1.apply(Client.scala:81)
at org.apache.spark.deploy.yarn.Client$$anonfun$1.apply(Client.scala:81)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.deploy.yarn.Client.<init>(Client.scala:80)
at org.apache.spark.deploy.yarn.YarnClusterApplication.start(Client.scala:1526)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:849)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassCastException: org.apache.hadoop.yarn.api.records.impl.pb.PriorityPBImpl cannot be cast to org.apache.hadoop.yarn.api.records.Priority
at org.apache.hadoop.yarn.api.records.Priority.newInstance(Priority.java:39)
at org.apache.hadoop.yarn.api.records.Priority.<clinit>(Priority.java:34)
... 15 more
But if I have only --conf "spark.executor.userClassPathFirst=true" then it hangs
I have solved the issue using maven shade plugin.
Ignore Spark Cluster Own Jars
Referrence video :
https://youtu.be/WyfHUNnMutg?t=23m1s
I followed answer given here and added the following.
Even in sourcecode SparkSubmit, you will see jar getting appended to total jar list if we give --jar so it will never override with those options but it will add jar
https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala#L644
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>okio</pattern>
<shadedPattern>com.shaded.okio</shadedPattern>
</relocation>
<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>com.shaded.okhttp3</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>log4j.properties</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

xmlbeans-maven-plugin not finding javac

I am trying to setup xmlbeans-maven-plugin 2.3.3 in my Eclipse and while everything seems to go OK, It fails with an java.io.IOException due to inability to find the file C:\Users\Daniel\Workspace\MyProject\javac.
This is strange because javac is on the system's %PATH% so why would it try to find it in %PROJECT_LOC%?
I found this problem description which sounds very similar to mine, but I placed the JDK path in front of all other paths and that didn't help.
Any idea how to tell the xmlbeans-maven-plugin where to look for javac?
UPDATE 1: I tried working around this problem by simply copying javac.exe to the project's directory and at least it now finds it but the problem moved forward to:
java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main" Could not find the main class: com.sun.tools.javac.Main. Program will exit.
Any insight that could help come up with the correct solution to this (e.g. something in .m2/settings.xml?) would be appreciated.
UPDATE 2: I also tried this little solution I found in my searches:
<settings 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/xsd/settings-1.0.0.xsd">
<localRepository>c:\maven\repository</localRepository>
<configuration>
<compiler>C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe</compiler>
</configuration>
</settings>
But that didn't help the plugin find javac. It still complains about "The system cannot find the file specified" for javac.exe.
Found the solution! In the project's pom.xml, simply add the following inside <configuration>:
<compiler>C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe</compiler>
i.e.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<schemaDirectory>${basedir}/src/main/xsd</schemaDirectory>
<compiler>C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe</compiler>
</configuration>
</plugin>
Also, be sure to point the Window -> Preferences -> Java -> installed JREs to the JDK's, not JRE's: C:\Program Files (x86)\Java\jdk1.6.0_37. As described in this thread.

Sonar and Jacoco : How to ? (Compatibility with Cobertura)

I know there are lot of questions about Sonar and Jacoco not generating the report correctly on SO but none of them helped me solve my problem:
Here is the deal :
I have a project using Cobertura to calculate code coverage and I can't change that. Sonar must use Cobertura for the server-side. But on the other hand I have this client (we're talking about a webapplication using smartGWT in java) which is tested with Selenium RC (because that's the only way to test smartGWT).
Cobertura can't calculate Selenium tests' coverage because those tests are done on the deployed application. Jacoco can calculate that because it is launched as a java agent. So everything is working fine on my computer. The jacoco.exec is generated successfully. But it seems that Sonar can't find how to read that file or maybe it's just cobertura and jacoco that are conflicted...
Here is the error that Jenkins generate :
[INFO] Surefire report directory: D:\JENKINS-SONAR\jobs\agepro PROTO\workspace\target\surefire-reports
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
Caused by: java.io.FileNotFoundException: D:\JENKINS-SONAR\jobs\agepro (Accès refusé)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
at org.jacoco.agent.rt_9w37ty.controller.LocalController.startup(LocalController.java:46)
at org.jacoco.agent.rt_9w37ty.JacocoAgent.init(JacocoAgent.java:83)
at org.jacoco.agent.rt_9w37ty.JacocoAgent.premain(JacocoAgent.java:165)
... 6 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
And here is my configuration of the surefire plugin :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath}</argLine>
<excludes>
<exclude>**/Selenium*.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>surefire-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- <argLine>-javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath}</argLine> -->
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/Selenium*.java</include>
</includes>
<goal>selenium-test</goal>
</configuration>
</execution>
</executions>
</plugin>
Do you see any mistake I could have made ? Or maybe I have to set another path for the jacoco jar or something else ? Thanks for your help anyway.
The name reportPath is a bit misleading.
The setting sonar.jacoco.reportPath needs to point to a file and not to a directory.
You seem to have set it to: D:\JENKINS-SONAR\jobs\agepro: But I think you mean D:\JENKINS-SONAR\jobs\agepro\jacoco.exec
On further inspection I noticed that the problem might be that you working directory "agepro PROTO" has a space in it.
This breaks the syntax for the java agent configuration. Can you get rid of the space(I don't know if destfile='${sonar.jacoco.reportPath}' would work)

maven jetty plugin log4j configuration

i have a java web app with maven.
i'm using jetty to run it during development (by using maven jetty plugin)
i've my log4j.properties file placed under src/main/resources and it is copied under WEB-INF/classes when deployed as expected.
in my log4j.properties file i defined a filter variable and when deployed it is also filtered with the real value.
in log4j.properties under src/main/resources;
log4j.appender.FILE.File = ${config-gui.log-file}
in log4j.properties under WEB-INF/classes (after deployed with filtering);
log4j.appender.FILE.File = /tmp/mylogfile.log
my problem is; i'm getting following error when i run mvn jetty:run
log4j:ERROR setFile(null,true) call failed.<br />
java.io.FileNotFoundException: (No such file or directory)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)
at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:215)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:132)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:441)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:88)
at com.pribas.bucherplayerconfiggui.util.LoggerUtil.getLogger(LoggerUtil.java:10)
at com.pribas.bucherplayerconfiggui.Initialization.<clinit>(Initialization.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.webapp.WebXmlConfiguration.newListenerInstance(WebXmlConfiguration.java:649)
at org.mortbay.jetty.webapp.WebXmlConfiguration.initListener(WebXmlConfiguration.java:630)
at org.mortbay.jetty.webapp.WebXmlConfiguration.initWebXmlElement(WebXmlConfiguration.java:367)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.initWebXmlElement(AbstractConfiguration.java:190)
at org.mortbay.jetty.webapp.WebXmlConfiguration.initialize(WebXmlConfiguration.java:289)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.initialize(AbstractConfiguration.java:133)
at org.mortbay.jetty.webapp.WebXmlConfiguration.configure(WebXmlConfiguration.java:222)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.configure(AbstractConfiguration.java:113)
at org.mortbay.jetty.webapp.WebXmlConfiguration.configureWebApp(WebXmlConfiguration.java:180)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.configureWebApp(AbstractConfiguration.java:96)
at org.mortbay.jetty.plus.webapp.Configuration.configureWebApp(Configuration.java:124)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1217)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:110)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo$1.filesChanged(AbstractJettyRunMojo.java:409)
at org.mortbay.util.Scanner.reportBulkChanges(Scanner.java:493)
at org.mortbay.util.Scanner.reportDifferences(Scanner.java:359)
at org.mortbay.util.Scanner.scan(Scanner.java:286)
at org.mortbay.util.Scanner$1.run(Scanner.java:246)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
i think this error is because of it sees log4j.properties file which is under src/main/resources (which has appender's file param is not acceptable) instead of under WEB-INF/classes one.
i want maven jetty plugin to ignore log4j.properties file which is under src/main/resources and sees the one under WEB-INF/classes.
how can i do this?
or if this error is not related the idea i have, how can i solve this?
thx in advance.
I think, you can hardly guarantee which of log4j.properties will be used on in your jar or in WEB-INF/classes. It depends on concrete classloader implementation (in Tomcat or Jetty) which can either see WEB-INF/classes/log4j.properties or WEB-INF/libs/yourlib.jar:/log4j.properties. So you need to filter here or there :)
Using maven profiles you can configure the <excludes> for your resources and use this profile for to build web application for Tomcat deployment.
Maybe better solution will be renaming /src/main/resources/log4j.properties to /src/main/resources/log4j-jetty.properties and then configure Log4j via jetty plugin to use that resource:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
...
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>log4j-jetty.properties</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>

Resources