我正在尝试执行下面的推土机示例。我的 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}));