energie
asked on
JAVA storeing files in META-INF directory
I stored an xml file in the JARs META-INF directory and want to read that file using a path relative to the JARs root
this is what I'm doing:
ClassLoader cl = Thread.currentThread().get ContextCla ssLoader() ;
URL url = cl.getResource( "META-INF/test.xml" );
Initializer init = new Initializer(new File(url.getFile()).getAbs olutePath( ));
The absolute path is returned as: C:/Jar_root/abc.jar!/META- INF/test.x ml
If I try to use this as a file path I get a FileNotFoundException due to a illegal path syntax.
I need to use it this because inside the jar i have an entry point function, and I want to be able to run this:
C:\Jar_root\java -jar abc.jar
inside this jar, the first thing it'll do is it needs to go to the xml file stored inside the META-INF directory to get some information.
and I can't figure why it's complaining about the FileNotFound. it's trying to get into the jar file, but it can't.
any help is much appreciated! thanks
this is what I'm doing:
ClassLoader cl = Thread.currentThread().get
URL url = cl.getResource( "META-INF/test.xml" );
Initializer init = new Initializer(new File(url.getFile()).getAbs
The absolute path is returned as: C:/Jar_root/abc.jar!/META-
If I try to use this as a file path I get a FileNotFoundException due to a illegal path syntax.
I need to use it this because inside the jar i have an entry point function, and I want to be able to run this:
C:\Jar_root\java -jar abc.jar
inside this jar, the first thing it'll do is it needs to go to the xml file stored inside the META-INF directory to get some information.
and I can't figure why it's complaining about the FileNotFound. it's trying to get into the jar file, but it can't.
any help is much appreciated! thanks
ASKER
Do you see where that problem comes from? i've tried what you suggested and it doesn't work. I dont think i made a syntatic error, I might be missing something somewhere
thanks
thanks
try moving your xml file outside META-INF.
ASKER
Hi 'objects',
unfortunatley, if i move the xml files outside the META-INF directory, i will not be able to even locate it using the class-loader, since that's one of the places it looks for files to load.
dang it, i know I'm so close to the answer.
if i look at this:
C:/Jar_root/abc.jar!/META- INF/test.x ml
i can see that it is TRYING to get to the META-INF directory inside this Jar file, if i manually unpack the jar file, i can confirm that there is a META-INF directory as expected.
I don't know what I am missing. :(
unfortunatley, if i move the xml files outside the META-INF directory, i will not be able to even locate it using the class-loader, since that's one of the places it looks for files to load.
dang it, i know I'm so close to the answer.
if i look at this:
C:/Jar_root/abc.jar!/META-
i can see that it is TRYING to get to the META-INF directory inside this Jar file, if i manually unpack the jar file, i can confirm that there is a META-INF directory as expected.
I don't know what I am missing. :(
> i will not be able to even locate it using the class-loader
Why do you think that? Try it and see :)
The meta-inf directory is not the place for data files.
Why do you think that? Try it and see :)
The meta-inf directory is not the place for data files.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
8-)
should do it