如题,在用maven建了一个java项目,然后运行mvn eclipse:eclipse后导入了MyEclipse,自己编写完了程序后用MyEclipse可以运行,而用 mvn clean compile exec:java -Dexec.mainClass="com.hand.App" 编译运行程序却报错,说找不到spring的配置文件ApplicationContext.xml,从早上整到现在,都快崩溃了,实在是不知道为什么,所以请教各位大神们!
报错信息如下:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [ApplicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [ApplicationContext.xml] cannot be opened because it does not exist
我的工程结构如下:
ApplicationContext.xml文件放在src/main/java文件夹的根目录下,我的主函数加载配置文件代码:ApplicationContext ctx=new ClassPathXmlApplicationContext("/ApplicationContext.xml");求各位大神指点迷津,感激不尽了!
确定你在这个项目中配置了MVN命令
改为ApplicationContext ctx=new ClassPathXmlApplicationContext("classpath:ApplicationContext.xml");试试
大锅你需要指定classpath
mvn clean compile exec:java -Dexec.mainClass="com.hand.App"
---->
mvn clean compile exec:java -Dexec.classpath=XXX -Dexec.mainClass="com.hand.App"
类似于这种
你可以尝试下.
我没怎么用过maven的命令行.
你打开tomcat的webapp目录下找到工程,看里面spring配置文件有没有被放进去,如果没有,在eclipise先右键执行maven clean,然后找到maven上面一点有个工程部署啥的重新部署下,然后在maven install,在看行不行,不行就百度spring配置文件没被加载在tomcat下面
估计你肯定要在maven install那报错,就是要工程要点工程重部署