I am trying to execute below dozer example. my xml file is located in the same location as my java file, but i am getting the file not found exception
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)
If i give the complete the file path it is working but i am getting the below exception
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)
source code
String file = "C:/UnitTest/Dozer/src/com/mapping/mapping.xml";
DozerBeanMapper mapper = new DozerBeanMapper(Arrays.asList(new String[]{file}));
Ok. I solved this..
I put the file in resources/META-INF/dozerBeanMapping.xml
and accessed the file by using:
String file = "META-INF/dozerBeanMapping.xml";
DozerBeanMapper mapper = new DozerBeanMapper(Arrays.asList(new String[]{file}));
I hope this will help you guys as well.