1

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
3
  • it seems, your $classpath is not included into -cp parameter value because it uses a semicolon as separator. it could look like -cp .;$CLASSPATH or similar Commented Nov 9, 2015 at 8:52
  • when i do that i am getting all java options . Commented Nov 9, 2015 at 8:59
  • did you do it as $JAVA_HOME/bin/java -Dlogfile=/root/MyAppLogs/dealer/app.log -cp .;$CLASSPATH com.util.TestCron? Commented Nov 9, 2015 at 9:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

still the same exception , please see the edited part in my question where i included the updated script as per your comments.
You can't use * in classpath. I suggest you find an introductory text on setting up classpath and make sure you understand it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.