Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
NoClassDefFoundError in spring example
shawn peter
Ranch Hand
Posts: 1325
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my main class
package org.arpit.javapostsforlearning; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; class Spring3HelloWorldMain { public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext beanFactory = new ClassPathXmlApplicationContext("spring3HelloWorld.xml"); Spring3HelloWorld myBean = (Spring3HelloWorld) beanFactory.getBean("Spring3HelloWorldBean"); myBean.printHello(); } }
this is my beanclass
package org.arpit.javapostsforlearning; public class Spring3HelloWorld { String name; public void printHello() { System.out.println("Hello World from "+name); } public String getName() { return name; } public void setName(String name) { this.name = name; } }
this is xml file
<?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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="Spring3HelloWorldBean" class="org.arpit.javapostsforlearning.Spring3HelloWorld"> <property name="name" value="arpit" /> </bean> </beans>
when i run the application it givesme bellow error
java.lang.NoClassDefFoundError: org/arpit/javapostsforlearning/Spring3HelloWorldMain Caused by: java.lang.ClassNotFoundException: org.arpit.javapostsforlearning.Spring3HelloWorldMain at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Exception in thread "main"
Vijitha Kumara
Bartender
Posts: 4116
72
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It is a CNF so you need to check what contains the classpath from where you execute this code unless you explicitly set the classpath. You could do the latter and see what happens ("java -cp <path to the classes/jars> MainClass")
SCJP 5 | SCWCD 5
[
How to ask questions
] [
Twitter
]
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Issue with XMLBeanFactory
re: basic question on Spring framework
AOP not getting invoked on my Target Bean Method --> Singer.perform() method
Dout in Around Advice
Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExcep
More...