推土机文件未找到异常

时间:2011-12-03 01:35:39

标签: dozer

我正在尝试执行下面的推土机示例。我的xml文件与我的java文件位于同一个位置,但我收到的文件未找到异常

Exception in thread "main" org.dozer.MappingException: Unable to locate dozer mapping file [dozerMapping.xml] in the classpath!
    at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:87)
    at org.dozer.util.MappingValidator.validateURL(MappingValidator.java:63)
    at org.dozer.loader.CustomMappingsLoader.loadFromFiles(CustomMappingsLoader.java:101)
    at org.dozer.loader.CustomMappingsLoader.load(CustomMappingsLoader.java:56)
    at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:213)
    at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:186)
    at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
    at com.mapping.CopyAttributes.main(CopyAttributes.java:28)

如果我给出完整的文件路径它正在工作,但我得到以下异常

Exception in thread "main" org.dozer.MappingException: java.net.MalformedURLException: unknown protocol: c
    at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
    at org.dozer.util.ResourceLoader.getResource(ResourceLoader.java:57)
    at org.dozer.util.DefaultClassLoader.loadResource(DefaultClassLoader.java:44)
    at org.dozer.util.MappingValidator.validateURL(MappingValidator.java:61)
    at org.dozer.loader.CustomMappingsLoader.loadFromFiles(CustomMappingsLoader.java:101)
    at org.dozer.loader.CustomMappingsLoader.load(CustomMappingsLoader.java:56)
    at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:213)
    at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:186)
    at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
    at com.mapping.CopyAttributes.main(CopyAttributes.java:28)
Caused by: java.net.MalformedURLException: unknown protocol: c
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at org.dozer.util.ResourceLoader.getResource(ResourceLoader.java:55)

源代码

    String file = "C:/UnitTest/Dozer/src/com/mapping/mapping.xml";
    DozerBeanMapper mapper = new DozerBeanMapper(Arrays.asList(new String[]{file}));

2 个答案:

答案 0 :(得分:7)

确定。我解决了这个问题..

我将文件放在resources/META-INF/dozerBeanMapping.xml中并使用以下方式访问该文件:

String file = "META-INF/dozerBeanMapping.xml";

DozerBeanMapper mapper = new DozerBeanMapper(Arrays.asList(new String[]{file}));

我希望这对你们也有帮助。

答案 1 :(得分:0)

您正在使用String file = "C:/...",错误提到它不会将C识别为有效协议。

您应该尝试使用file://C:/... - 它可能有所帮助。如果没有,请尝试使用双反斜杠(C:\\UnitTest\\...),如果这不起作用,只需将文件上传到某处