Java Maven NoClassDefFoundError

59 Views Asked by At

In my Maven project I'm trying to run the FitNesse jar with the command bellow:

PS C:\path\to\fitnesse\repository\org\fitnesse\fitnesse\20231203> java -jar fitnesse-20231203.jar -p 8080

But I'm getting an error, even though I have downloaded the apache commons lang3 and added to maven dependencies

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.14.0</version>
</dependency>
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils      
        at fitnesse.util.StringUtils.replace(StringUtils.java:37)                                    
        at fitnesse.testsystems.slim.tables.SlimTableFactory.addTableType(SlimTableFactory.java:54)  
        at fitnesse.testsystems.slim.tables.SlimTableFactory.<init>(SlimTableFactory.java:26)        
        at fitnesse.ContextConfigurator.makeFitNesseContext(ContextConfigurator.java:152)            
        at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:73)                            
        at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:60)                            
        at fitnesseMain.FitNesseMain.main(FitNesseMain.java:40)                                      
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils                    
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)   
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        ... 7 more

I have tried only downloading the commons lang3 jar and nothing besides that

1

There are 1 best solutions below

1
Fried Hoeben On

To run FitNesse directly with a command line similar to what you've got you should use the 'standalone' jar. This will include all dependencies of FitNesse itself so will allow you to run the wiki. This is a separate artifact in maven central.

But I would recommend against running FitNesse this way, since you will also need to create wiki content and access Java fixture code to actually define how to connect the system you want to test to the wiki. Downloading the jar to a new directory of your choice, where you can then also place your 'plugins.properties' file and starting from there will give you a better experience. This also makes it easier to place your test content in version control, or manually keep track of it should you prefer that.

I personally found setting up to get started with FitNesse quite a hassle. Especially since before you can actually start testing you also need to write the 'fixtures' that will allow FitNesse to actually perform some tests. To make this easier I created a 'template project' which you can use to get started with your own FitNesse project. Besides FitNesse it also includes some fixtures to allow you to get started writing tests on web based applications immediately. Even if you don't to use my fixtures, other pre-defined fixtures exist, it might provide a good starting point to see how you can setup your own test project using Maven (both to run tests locally and to run them on a server as part of a CI/CD pipeline).