Reputation: 32321
This is my simple program
First of all , log4j is present under WEB-INF/lib directory .
package com.util;
import org.apache.log4j.Logger;
public class TestCron {
static Logger logger = Logger.getLogger(TestCron.class);
public static void main(String[] args) {
System.out.println("sysout sattement for sample ");
logger.error("This should appear inside dealer logs");
}
}
I have got a script which I am trying to run manually in Linux.
#!/bin/bash
cd /usr/local/tomcat7/webapps/Test/WEB-INF/classes/
JAVA_HOME=/opt/jdk1.7.0_67
CLASSPATH=/usr/local/tomcat7/webapps/Test/WEB-INF/lib/*: .
$JAVA_HOME/bin/java -Dlogfile=/root/MyAppLogs/dealer/app.log -cp . $CLASSPATH com.util.TestCron
I am getting the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
Could you please tell me how to resolve this issue ?
Edited part
#!/bin/bash
cd /usr/local/tomcat7/webapps/OMS/WEB-INF/classes/
JAVA_HOME=/opt/jdk1.7.0_67
CLASSPATH=/usr/local/tomcat7/webapps/OMS/WEB-INF/lib/*: .
$JAVA_HOME/bin/java -Dlogfile=/root/OrientAppLogs/dealer/app.log -cp .:$CLASSPATH com.util.TestCron
Upvotes: 1
Views: 1747
Reputation: 7804
In your invocation I see -cp . $CLASSPATH
. File separator used in classpath is :
on linux environment, therefore only current directory is included in the classpath.
I think you need to change it to -cp .:$CLASSPATH
Upvotes: 1