我把别人的项目放在自己的机器上运行出了个问题,想请教大家。
这个项目是用spring+hibernate+struts框架的里面用JUNIT写了个测试类 
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;import junit.framework.TestCase;public class InitSystemDatasTest extends TestCase {
private static BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
public void testAddOrUpdateInitDatas() {
InitSystemDatas init = (InitSystemDatas)factory.getBean("initSystemDatas");
init.addOrUpdateInitDatas("init_datas.xml");
}}
我在运行这个测试类的testAddOrUpdateInitDatas() 方法时,出现了异常,如下:
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at junit.framework.TestSuite.createTest(TestSuite.java:54)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:280)
at junit.framework.TestSuite.<init>(TestSuite.java:140)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.IllegalArgumentException: Resource path [E:\灏氬鍫?OA绯荤粺\_OA_鍘熶唬鐮?\oa_12\WebRoot\WEB-INF\classes] does not denote a directory
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.retrieveMatchingFiles(PathMatchingResourcePatternResolver.java:489)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindMatchingFileSystemResources(PathMatchingResourcePatternResolver.java:469)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:452)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:321)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:255)
at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:768)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:141)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:168)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:294)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
at com.bjsxt.oa.managers.InitSystemDatasTest.<clinit>(InitSystemDatasTest.java:9)
... 13 more
附加:InitSystemDatasImpl类如下:
import java.util.Iterator;
import java.util.List;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;import com.bjsxt.oa.managers.InitSystemDatas;
import com.bjsxt.oa.managers.OrgManager;
import com.bjsxt.oa.managers.SystemException;
import com.bjsxt.oa.managers.UserManager;
import com.bjsxt.oa.model.ACL;
import com.bjsxt.oa.model.FieldInput;
import com.bjsxt.oa.model.FieldType;
import com.bjsxt.oa.model.Module;
import com.bjsxt.oa.model.Organization;
import com.bjsxt.oa.model.Permission;
import com.bjsxt.oa.model.Person;
import com.bjsxt.oa.model.Role;
import com.bjsxt.oa.model.User;public class InitSystemDatasImpl extends AbstractManager implements
InitSystemDatas {
private static Log logger = LogFactory.getLog(InitSystemDatasImpl.class);
private String file;
private OrgManager orgManager;
private UserManager userManager;

public void addOrUpdateInitDatas(String xmlFilePath){
try {
String filePath = null;
if(xmlFilePath == null || xmlFilePath.trim().equals("")){
filePath = file;
}else{
filePath = xmlFilePath;
}

//DOM4J使用示例
Document document = new SAXReader().read(
Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath)
);

importModules( document.selectNodes("//Modules/Module") ,null);
importRoleAndAcl(document.selectNodes("//Roles/Role"));
importOrgAndPerson(document.selectNodes("//Organizations/Org"),null); importFieldDefinition(document.selectNodes("//FieldTypes/FieldType"),document.selectNodes("//FieldInputs/FieldInput"));
} catch (Exception e) {
e.printStackTrace();
throw new SystemException("初始化数据生成有误!");
}
}
//导入模块信息
protected void importModules(List modules,Module parent){

for (Iterator iter = modules.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
Module module = new Module();
module.setName(element.attributeValue("name"));
module.setSn(element.attributeValue("sn"));
module.setUrl(element.attributeValue("url"));
module.setOrderNo(Integer.parseInt(element.attributeValue("orderNo")));
module.setParent(parent);
getHibernateTemplate().save(module);
logger.info("导入模块【"+module.getName()+"】");
importModules( element.selectNodes("Module") , module);
}
}

.......(省略)
}Caused by: java.lang.IllegalArgumentException: Resource path [E:\灏氬鍫?OA绯荤粺\_OA_鍘熶唬鐮?\oa_12\WebRoot\WEB-INF\classes] does not denote a directory  
我想,问题应该出在这句话吧 Document document = new SAXReader().read(
Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath)
);
这个问题该如何解决呢?路径显示错误了,找不到该目录,但我的电脑里明明有那个目录的呀,谢谢指教!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【ppliveonline】截止到2008-07-15 17:28:43的历史汇总数据(不包括此帖):
    发帖的总数量:9                        发帖的总分数:280                      每贴平均分数:31                       
    回帖的总数量:5                        得分贴总数量:1                        回帖的得分率:20%                      
    结贴的总数量:2                        结贴的总分数:40                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:7                        未结的总分数:240                      
    结贴的百分比:22.22 %               结分的百分比:14.29 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主该结一些帖子了
      

  2.   

    你的路径中是不是有中文呀  java不识别中文  你把文件夹名换成英文试试呀
      

  3.   

    java.lang.IllegalArgumentException: Resource path [E:\灏氬鍫?OA绯荤粺\_OA_鍘熶唬鐮?\oa_12\WebRoot\WEB-INF\classes] does not denote a directory
    路径对否 中文 空格