New Module developemnt java.lang.NoClassDefFoundError exception

Hi,

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 basicexampleService.java 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(  ){
		try
		{
		      BasicExampleService bs=Context.getService(BasicExampleService.class)
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
		return "test";
	}

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

WebApplicationInitializer

public class Initializer implements WebApplicationInitializer
{
	@Override
	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( "/" );
	}
}

Config

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

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

moduleApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
      		    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      		    http://www.springframework.org/schema/context
      		    http://www.springframework.org/schema/context/spring-context-3.0.xsd
      		    http://www.springframework.org/schema/jee
      		    http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
      		    http://www.springframework.org/schema/tx
      		    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      		    http://www.springframework.org/schema/aop
      		    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      		    http://www.springframework.org/schema/util
      		    http://www.springframework.org/schema/util/spring-util-3.0.xsd">

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

    	
    	<!-- Services accessible via Context.getService() -->
    	<bean parent="serviceContext">
    		<property name="moduleService">
    			<list>
    				<value>${project.parent.groupId}.${project.parent.artifactId}.api.BasicExampleService</value>
    				<bean
    					class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    					<property name="transactionManager">
    						<ref bean="transactionManager" />
    					</property>
    					<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>
    								</bean>
    							</property>
    						</bean>
    					</property>
    					<property name="preInterceptors">
    						<ref bean="serviceInterceptors" />
    					</property>
    					<property name="transactionAttributeSource">
    						<ref bean="transactionAttributeSource" />
    					</property>
    				</bean>
    			</list>
    		</property>
    	</bean>
    	
    </beans>

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

@dkayiwa Thanks for reply. Repo Link https://github.com/arun472/OpenMrsTestWebApp

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: https://wiki.openmrs.org/display/docs/Creating+Modules

@dkayiwa Thanks for reply.