0

My project looks something like this

maven-simple

    src/main/java         
    src/main/resources
    src/test/java
        -com.org.central
          -CommonMethods.java
    src/test/resources

    pom.xml

I am trying to create a jar file through this method in eclipse for the above project

  1. Right Click -> Export -> Java -> Jar File
  2. click Next -> Next -> Finish

exported jar file has been created in the path . Then i am importing this jar file in some other project(for ex:- project b) to use the CommonMethods.java

But i am getting this error

 ←[31mjava.lang.NoClassDefFoundError: com/org/central/CommonMethods
 at stepDefinitions.Check.iSeeElement(Check.java:14)    
 Caused by: java.lang.ClassNotFoundException:  com.org.central.CommonMethods
 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)
 at stepDefinitions.Check.iSeeElement(Check.java:14)

what have i done wrong ?

user1553680
  • 339
  • 3
  • 6
  • 18
  • You should really take a look to Maven documentations : http://stackoverflow.com/documentation/maven/topics & http://maven.apache.org/index.html – Mickael Sep 06 '16 at 12:38
  • You need to include your dependencies in your classpath. Make a jar with dependencies (linked question) or use a custom classpath. – Tunaki Sep 06 '16 at 13:17

1 Answers1

0

Your jar must contain .class files, not only .java files.

Run a mvn clean install, and you'll get your jar containing the classes.

BTW, always (A L W A Y S), start your class names with uppercase letters.

Andres
  • 10,561
  • 4
  • 45
  • 63