0

I am building a project in a Windows Eclipse environment and then trying to test the project jar using the test jar in a Unix environment . When I run I get what is shown below. I am using Maven with the assembly plugin to package the project with the Test Jar and I can see the class that is supposedly missing inside the jar when I run the -tf command.

java -cp MyServerTest.jar:junit.jar junit.runner.JunitCore com.MyServer.services.ZoweAuthServiceTest

Results in:

java.lang.NoClassDefFoundError: com.MyServer.services.ZoweAuthService at com.MyServer.services.ZoweAuthServiceTest.testQueryToZowe(ZoweAuthServ iceTest.java:40) Caused by: java.lang.ClassNotFoundException: com.MyServer.services.ZoweAuthService

  • I would advice that you add some code into your question. It will increase the chances of getting an answer and reduce the chances of having your question flagged and removed. – acarlstein Apr 30 '19 at 15:28
  • I guess you are running java command in a wrong place. you should put the ZoweAuthServiceTest class in the com/MyServer/services/ZoweAuthServiceTest.java path and run the command from the base folder – Mohsen Apr 30 '19 at 15:35
  • Have you tried executing `mvn test` instead of manually calling the test from the command line? – The Head Rush Apr 30 '19 at 17:22
  • I am using a special version of Unix that does not have mvn. – James Henderson Apr 30 '19 at 17:35

2 Answers2

0

You could use the main answer from this post:

How to run JUnit test cases from the command line

Make sure to running from the current directory of your jar and adjust it accordingly to junit version.

0

I figured it out. I guess I should have mentioned I am using spring-boot. Spring places the main classes of my project under a special prefix in the jar file "BOOT-INF" which prevents the test class from finding the class it wants to test. I added the classifer exec to my pom. This creates two separate jars. One for executing and one that has the normal class references for testing.

`<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <classifier>exec</classifier>
    </configuration>
</plugin>`