Loading resources from another maven module with mvn exec:java doesn't work -
i have maven project structure:
parent -----module1 --------src ------------main -----------------java ----------------------loader.java -----------------resources -------------------------file1.txt -----module2 --------src ------------main -----------------java -------------------------callloader.java so loader.java, loads files1.txt. call class callloader.java module2. code used
in loader.java,
private static file getresourcefile(string filename){ try { url resource = graphutil.class.getclassloader().getresource(filename); return new file(resource.getpath()); } catch (throwable e) { throw new runtimeexception("couldn't load resource: "+filename, e); } } where filename="file1.txt".
i error because file absolute path looks this:
file:/home/moha/.m2/repository/my/package/name/%7bproject.version%7d/base-%7bproject.version%7d.jar!/file1.txt what doing wrong?
get content of file stream instead in order able read resource jar file root cause of issue. in other words use getresourceasstream instead of getresource.
you can return url instead of file call openstream() later read if needed.
nb1: url of type jar:file/... cannot managed class file
nb2: convert url file, correct code new file(resource.touri())
Comments
Post a Comment