0

I'm new to maven and I was trying to learn using external dependency. So, I used to Log4j library and put the jar file in /src/lib folder (Using eclipse)enter image description here

I can run the code from eclipse (It just asks to initialize log4j property file) I'm trying to run on the command line. So, I did "mvn clean install" in the project folder and then went to target/classes and try to run command "java com.siddhant.samplemavenproject1.App), it gives me an error Exception in thread "main" java.lang.NoClassDefFoundError:

org/apache/log4j/Logger
    at com.siddhant.samplemavenproject1.App.main(App.java:14)
    Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more 

App.java file is like:

package com.siddhant.samplemavenproject1;
   import org.apache.log4j.Logger;





   public class App 
   {
       public static void main( String[] args )
       {            Logger logger = Logger.getLogger(App.class.getSimpleName());
            System.out.println( "Hello World!" );
            //Util.printMessage("This is my sample message");
            logger.info("This is logger message");
        }
    }

PS: I also installed the external library in local repository using command "mvn install:install-file -Dfile=/Users/siddhantjawa/Documents/testworkspace/samplemavenproject1/src/lib/log4j.jar -DgroupId=com.siddhant -DartifactId=log4j -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar".

user2430771
  • 1,326
  • 4
  • 17
  • 33
  • @Scary: Can you point out where it has been solved. I searched on stack overflow but the didn't find the solution. – user2430771 Feb 08 '17 at 02:30
  • Hi @user2430771 the link is at the top of this question, but if you can not find it, here it is again http://stackoverflow.com/questions/17408769/how-do-i-resolve-this-java-class-not-found-exception – Scary Wombat Feb 08 '17 at 02:33
  • Wrong idea. Just add the dependency to your pom file and that's it....don't start using a lib folder this is wrong. – khmarbaise Feb 08 '17 at 08:08

0 Answers0