java - How to run maven project in IntelliJ that requires a file to be in class path? -


i studying book , having difficulty running example code.

the code causing problem is:

public static void main(string[] args) {     classpathxmlapplicationcontext applicationcontext = new classpathxmlapplicationcontext("/com/wiley/beginningspring/ch2/ch2-beans.xml"); 

the error getting is:

exception in thread "main" org.springframework.beans.factory.beandefinitionstoreexception: ioexception parsing xml document class path resource [com/wiley/beginningspring/ch2/ch2-beans.xml]; nested exception java.io.filenotfoundexception: class path resource [com/wiley/beginningspring/ch2/ch2-beans.xml] cannot opened because not exist

what tried is, in intellij, imported code maven project , did clean install:

[info] --- maven-install-plugin:2.4:install (default-install) @ xml-based-configuration --- [info] installing /users/koraytugay/downloads/spring-book-ch2/xml-based-configuration/target/xml-based-configuration-0.0.1-snapshot.jar /users/koraytugay/.m2/repository/com/wiley/beginningspring/xml-based-configuration/0.0.1-snapshot/xml-based-configuration-0.0.1-snapshot.jar [info] installing /users/koraytugay/downloads/spring-book-ch2/xml-based-configuration/pom.xml /users/koraytugay/.m2/repository/com/wiley/beginningspring/xml-based-configuration/0.0.1-snapshot/xml-based-configuration-0.0.1-snapshot.pom [info] ------------------------------------------------------------------------ [info] build success 

then right click on main method in main.java , click run, getting error

"/com/wiley/beginningspring/ch2/ch2-beans.xml" 

is not found in classpath. right way solve this?

my run configuration follows:

enter image description here

edit 01: can make example work want understand classpath solution:

filesystemxmlapplicationcontext applicationcontext = new filesystemxmlapplicationcontext("/users/koraytugay/downloads/spring-book-ch2/xml-based-configuration/src/main/java/com/wiley/beginningspring/ch2/ch2-beans.xml"); 

edit 02: solution worked: enter image description here

typically resources wouldn't put in src/main/java, rather src/main/resources. resources contains files maven copy classpath of build artifact. java contains files aren't copied build artifact (the .java files aren't copied artifact, neither xml file be)

try moving ch2-beans.xml main resources while preserving rest of path.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -