New Module developemnt java.lang.NoClassDefFoundError exception


I have created a new module (default basicexample )by using Maven Archetype mvn module-wizard:generate -s settings.xml .
The project structure was generated but when i am trying to access basicexampleService from a controller in omod module was defined in api module using api Context.getService(BasicExampleService.class); i am getting an exception

@RequestMapping( value = "/test", method = RequestMethod.GET )
	public @ResponseBody String test(  ){
		      BasicExampleService bs=Context.getService(BasicExampleService.class)
		catch ( Exception e )
		return "test";

Caused by: java.lang.NoClassDefFoundError: org/openmrs/module/basicexample/api/BasicExampleService
	at org.openmrs.module.basicexample.controller.TestController.test21(


public class Initializer implements WebApplicationInitializer
	public void onStartup( final ServletContext servletContext ) throws ServletException
		AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
		rootContext.register( CandoApplicationContext.class );
		//Context loader listener
		servletContext.addListener( new ContextLoaderListener( rootContext ) );
		DispatcherServlet dispatcherServlet = new DispatcherServlet( rootContext );
		//Dispatcher servlet
		ServletRegistration.Dynamic dispatcher =servletContext.addServlet( "dispatcher", dispatcherServlet );
		dispatcher.setLoadOnStartup( 1 );
		dispatcher.addMapping( "/" );


@ComponentScan( basePackages = {"org.openmrs.**"} )
@ImportResource( value = {  "classpath*:applicationContextservice.xml","classpath*:moduleApplicationContext.xml", "classpath*:webModuleApplicationContext.xml"})
public class CandoApplicationContext extends WebMvcConfigurerAdapter
	public CandoApplicationContext()

Can we look at your moduleApplicationContext.xml? Or the entire module source?


<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
    	xmlns:xsi="" xmlns:p=""
    	xmlns:jee="" xmlns:tx=""
    	xmlns:aop="" xmlns:util=""

    	<!-- Add here beans related to the API context -->

    	<!-- Services accessible via Context.getService() -->
    	<bean parent="serviceContext">
    		<property name="moduleService">
    					<property name="transactionManager">
    						<ref bean="transactionManager" />
    					<property name="target">
    						<bean class="${project.parent.groupId}.${project.parent.artifactId}.api.impl.BasicExampleServiceImpl">
    							<property name="dao">
    								<bean class="${project.parent.groupId}.${project.parent.artifactId}.api.db.hibernate.HibernateBasicExampleDAO">
    									<property name="sessionFactory">
    										<ref bean="sessionFactory" />
    					<property name="preInterceptors">
    						<ref bean="serviceInterceptors" />
    					<property name="transactionAttributeSource">
    						<ref bean="transactionAttributeSource" />

This looks fine. Can we look at the rest of the module?

@dkayiwa Thanks for reply. Repo Link

I see that you trying to package the module as a war file. This is not correct. Change back to the default packaging. OpenMRS modules are not packaged as war files. Take a look at this for more module information:

@dkayiwa Thanks for reply.