maven test시 resource 경로
The classpath mechanism does not work for files. Relative file paths are resolved from the current directory, not from the classpath elements.
So you could just do
File xmlFile = new File("target/test-classes/xxxx.xml");
File xsdFile = new File("target/test-classes/xxxx.xsd");
However, a much cleaner solution would be to work with InputStreams instead of files. Almost every library that supports
File
parameters also supports InputStream
parameters. And that way you can use ClassLoader
magic without manually specifying any paths:ClassLoader cldr = Thread.currentThread().getContextClassLoader();
InputStream xmlStream = cldr.getResourceAsStream("xxxx.xml");
InputStream xsdStream = cldr.getResourceAsStream("xxxx.xsd");
Reference:
- Byte Streams (Sun Java Tutorial)
ClassLoader
(javadoc)InputStream
(javadoc)
댓글
댓글 쓰기