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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -