views:

192

answers:

2

I have a java desktop app (main project) and another project with a series of packages in NetBeans. Some of the packages use spring for JDBC and IOC.

I am getting the following error when running in debug:

Caused by: java.io.FileNotFoundException: class path resource [config.xml] cannot be opened because it does not exist

Where is the config file supposed to go? Where exactly is the class path? Is it in dist, build, in the root of the project that calls spring, or the main project (the desktop app)?

confused ..

A: 

Your classpath is defined when you run your app using the java command. You can specify it using:

java -cp $path my.Main

where $path is your classpath. It is a :-separated (; on windows) list of JAR files and/or directories containing compiled .class files.

If you run your program like:

java -cp configdir my.Main

And put your spring config in configdir (the fully-qualified path) then that should be discovered.

NetBeans: whilst I'm not a netbeans user, it probably offers a number of ways for you to complete the task you want:

  1. In your run configuration (i.e. where you define what class is being run, what the command-line parameters are etc), you will probably be able to add items to the classpath. These might be directories or individual files

  2. In your compiler settings, you can probably tell NetBeans to automatically copy files of a certain type (like properties files, XML config files) from your source locations to where NetBeans puts your class files.

  3. If you put your config.xml file in the directory where NetBeans is compiling your .class files to

oxbow_lakes
Im really sorry, I don't understand - I don't run the project from the command line, I just run it in netbeans from the debug menu. Is the config directory on the main project's path? or the project that actually looks for the spring file?
jimurphy
I've edited the answer. It's often a good idea to understand the "raw" java tools like `javac`, `java` before using an IDE. The IDE's settings basically just translate into arguments to these raw tools. It means that it's easier moving IDEs as well!
oxbow_lakes
A: 

Put it in the root folder of you application

if you created your application in a folder called Spring then you should put your file in that folder

Ashraf Fouda