|
|
Error in simple example: class path resource cannot be opened because it
Hello,
I am tryng to learn Spring for a study project
I am trying this simple firs example, in this zip file you can find the sources of it: guide/ing/java_spring/esempio_01.zip
I use NetBeans and I have created a new project as Java Application.
When I try to run the ReportClient.java class (the class that contain the main() ) NetBeans give me the following errors:Code:
run:
8-giu-2010 12.18.03 org..beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
Exception in thread quot;mainquot; org..beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist at org..beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349) at org..beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310) at org..beans.factory.xml.XmlBeanFactory.lt;initgt;(XmlBeanFactory.java:73) at org..beans.factory.xml.XmlBeanFactory.lt;initgt;(XmlBeanFactory.java:61) at it.html.spring.report.ReportClient.main(ReportClient.java:13)
Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist at org..core.io.ClassPathResource.getInputStream(ClassPathResource.java:143) at org..beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ... 4 more
Java Result: 1
COSTRUITO CON SUCCESSO (tempo totale: 0 secondi)
Seem like it doesn't find the beans.xml file but I don't understand why...because this file is in the src directory !!!
Please can you help me to solve this problem !!!
Tnx
Andrea
The problem seems to be in the your NetBeans configuration - from the command line it works nicely:
Jun 8, 2010 4:22:12 PM org..beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
genera txt report
File salvato
.uclClassLoader$1.run(uclClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.uclClassLoader.findClass(uclClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: javaapplication6.Main. Program will exit.
andrea@andrea-laptop:~/NetBeansProjects/JavaApplication6/dist$
So...I think that javaapplication6 is the name of the project and maybe it try to execute a class name Main so I have try to decompress this JavaApplication6.jar in a folder and to execute the ReportClient class that contain the main method but if I try to do this I have the following errorCode:
andrea@andrea-laptop:~/NetBeansProjects/JavaApplication6/dist/JavaApplication6/it/html/spring/report$ java ReportClient
Exception in thread quot;mainquot; java.lang.NoClassDefFoundError: ReportClient (wrong name: it/html/spring/report/ReportClient)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.uclClassLoader.defineClass(uclClassLoader.java:283)
at java.net.uclClassLoader.access$000(uclClassLoader.java:58)
at java.net.uclClassLoader$1.run(uclClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.uclClassLoader.findClass(uclClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: ReportClient. Program will exit.
Also if I try to execute the executable file in the bin directory of the zip file (guide/ing/java_spring/esempio_01.zip) I have the same problem !!!
Please can you help me to undestand where is the problem and say me how I have to do to solve? it's very very important because I am stopped with my project :-/
Thanks
Andrea
I have no idea what you JavaApplication6,jar is and what it contains, but if I execute the follwing command in your bin directory
Code:
java -cp .;D:\somewhere\org..beans-3.0.2.RELEASE.jar;D:\somewhere\org..core-3.0.2.RELEASE.jar;W:\05_tools\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar it/html/spring/report/ReportClient gt;1 2gt;amp;1
It produces
Jun 8, 2010 6:08:50 PM org..beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
genera txt report
File salvato
(assuming that D:\somewhere contains Spring jars).
mmm ok...wait...I have not well understand what you have do !!!
In addition to class Testclient you also run some other files at the same time?
If is so...maybe the problem is that I don't know well how to execute a Spring application (the professor don't say nothing about it during the curse)
Please can you explain me better this thing?
Thanks
Andrea
Your problems are completely unrelated to Spring, you do not know the very basic things about Java Things that are the absolute must for any Java developer (even the student)
Take a look on the javac/java documentation, for example here
javase/6/docs/te...dows/java.html
and here
javase/6/docs/te...vac/index.html
To put it short - I just specified (using -cp switch) which directories and jars are on classpath (in this case besides your bin directory, which was the curret one, there are quot;basicquot; Spring jars as well as and commons-logging required by Spring.
Originally Posted by AndreaNobilimmm ok...wait...I have not well understand what you have do !!!
In addition to class Testclient you also run some other files at the same time?
If is so...maybe the problem is that I don't know well how to execute a Spring application (the professor don't say nothing about it during the curse)
Please can you explain me better this thing?
Thanks
Andrea |
|