You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Denise Wu <wa...@gmail.com> on 2011/08/02 16:33:41 UTC

How to read file from META-INF

Hi,

I have a "mySchema.xsd" located in the META-INF directory in the
webservice archive file myService.aar.
I would like to read this file "mySchema.xsd" in my webservice class.
How to access it at runtime?

Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Re: How to read file from META-INF

Posted by Thomas Grabietz <to...@toms-toy.de>.
Hi Denise,

maybe you need the absolut path to open the file:

MessageContext msgContext = MessageContext.getCurrentMessageContext();
		ServletContext context = ((HttpServlet)
msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext();
		String path = context.getRealPath("/");

regards Tom


Am 06.12.2011 13:32, schrieb Kishanthan Thangarajah:
> Hi Denise,
> 
> On Tue, Aug 2, 2011 at 8:03 PM, Denise Wu <wa...@gmail.com> wrote:
>> Hi,
>>
>> I have a "mySchema.xsd" located in the META-INF directory in the
>> webservice archive file myService.aar.
>> I would like to read this file "mySchema.xsd" in my webservice class.
>> How to access it at runtime?
> 
> I think you can access the file by using
> getResourceAsStream("path/to/file") to read the file at run time.
> 
> Hope this helps.
> 
> Thanks,
> Kishanthan.
>>
>> Thank you.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
>> For additional commands, e-mail: java-dev-help@axis.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-user-help@axis.apache.org
> 


-- 
Für's private
http://toms-toy.de/Thomas%20Grabietz%20tom@toms-toy.de%20(0xE43515AC)%20pub.asc

GIT d-(---)? s():()> a+ C$>++ UL$>+ P? L>++ E W>+++ N>++$ o K--? w>--- O
M>-- V PS>+ PE Y PGP>++$ t 5 X R tv b>+++ DI D G e> h>++ !r y>+

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: How to read file from META-INF

Posted by Kishanthan Thangarajah <ks...@gmail.com>.
Hi Denise,

On Tue, Aug 2, 2011 at 8:03 PM, Denise Wu <wa...@gmail.com> wrote:
> Hi,
>
> I have a "mySchema.xsd" located in the META-INF directory in the
> webservice archive file myService.aar.
> I would like to read this file "mySchema.xsd" in my webservice class.
> How to access it at runtime?

I think you can access the file by using
getResourceAsStream("path/to/file") to read the file at run time.

Hope this helps.

Thanks,
Kishanthan.
>
> Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-dev-help@axis.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: How to read file from META-INF

Posted by Denise Wu <wa...@gmail.com>.
Nothing worked, I finally copied my xsd file into the 'classes'
directory that contain the service implementation classes, and then
read the xsd file using the following code from my service
'implementation class':

InputStream input = getClass().getResourceAsStream("BookReservation.xsd");
            	
StringBuilder sb = new StringBuilder();
String line;

BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));

while ((line = reader.readLine()) != null) {
	
	          sb.append(line).append("\n");
	          System.out.println("sb.toString()");
						  }


Thanks.

On Fri, Aug 5, 2011 at 1:48 AM, Deepal Jayasinghe <de...@opensource.lk> wrote:
> Have a look at the following:
> http://wso2.org/library/259
>
> Thanks,
> Deepal
>> Hi,
>>
>> I tries all combinations using the getResource in calssloader but it's
>> not working.
>> Can you point to a sample code example please?
>>
>> Many thanks
>>
>>
>>
>> On Tue, Aug 2, 2011 at 4:24 PM, Deepal Jayasinghe <de...@gmail.com> wrote:
>>> You can get the class loader  and read the file using getResource as
>>> stream. Once you ask for the class loader it will give you the class
>>> loader that Axis2 has used to load the your service class.
>>>
>>> Thanks.
>>> Deepal
>>>
>>> On Tue, Aug 2, 2011 at 10:33 AM, Denise Wu <wa...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have a "mySchema.xsd" located in the META-INF directory in the
>>>> webservice archive file myService.aar.
>>>> I would like to read this file "mySchema.xsd" in my webservice class.
>>>> How to access it at runtime?
>>>>
>>>> Thank you.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
>>>> For additional commands, e-mail: java-user-help@axis.apache.org
>>>>
>>>>
>>>
>>>
>>> --
>>> http://blogs.deepal.org
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
>>> For additional commands, e-mail: java-user-help@axis.apache.org
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-user-help@axis.apache.org
>
>



-- 
Wadienil.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: How to read file from META-INF

Posted by Deepal Jayasinghe <de...@opensource.lk>.
Have a look at the following:
http://wso2.org/library/259

Thanks,
Deepal
> Hi,
>
> I tries all combinations using the getResource in calssloader but it's
> not working.
> Can you point to a sample code example please?
>
> Many thanks
>
>
>
> On Tue, Aug 2, 2011 at 4:24 PM, Deepal Jayasinghe <de...@gmail.com> wrote:
>> You can get the class loader  and read the file using getResource as
>> stream. Once you ask for the class loader it will give you the class
>> loader that Axis2 has used to load the your service class.
>>
>> Thanks.
>> Deepal
>>
>> On Tue, Aug 2, 2011 at 10:33 AM, Denise Wu <wa...@gmail.com> wrote:
>>> Hi,
>>>
>>> I have a "mySchema.xsd" located in the META-INF directory in the
>>> webservice archive file myService.aar.
>>> I would like to read this file "mySchema.xsd" in my webservice class.
>>> How to access it at runtime?
>>>
>>> Thank you.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
>>> For additional commands, e-mail: java-user-help@axis.apache.org
>>>
>>>
>>
>>
>> --
>> http://blogs.deepal.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
>> For additional commands, e-mail: java-user-help@axis.apache.org
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: How to read file from META-INF

Posted by Denise Wu <wa...@gmail.com>.
Hi,

I tries all combinations using the getResource in calssloader but it's
not working.
Can you point to a sample code example please?

Many thanks



On Tue, Aug 2, 2011 at 4:24 PM, Deepal Jayasinghe <de...@gmail.com> wrote:
> You can get the class loader  and read the file using getResource as
> stream. Once you ask for the class loader it will give you the class
> loader that Axis2 has used to load the your service class.
>
> Thanks.
> Deepal
>
> On Tue, Aug 2, 2011 at 10:33 AM, Denise Wu <wa...@gmail.com> wrote:
>> Hi,
>>
>> I have a "mySchema.xsd" located in the META-INF directory in the
>> webservice archive file myService.aar.
>> I would like to read this file "mySchema.xsd" in my webservice class.
>> How to access it at runtime?
>>
>> Thank you.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
>> For additional commands, e-mail: java-user-help@axis.apache.org
>>
>>
>
>
>
> --
> http://blogs.deepal.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-user-help@axis.apache.org
>
>



-- 
Wadienil.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: How to read file from META-INF

Posted by Deepal Jayasinghe <de...@gmail.com>.
You can get the class loader  and read the file using getResource as
stream. Once you ask for the class loader it will give you the class
loader that Axis2 has used to load the your service class.

Thanks.
Deepal

On Tue, Aug 2, 2011 at 10:33 AM, Denise Wu <wa...@gmail.com> wrote:
> Hi,
>
> I have a "mySchema.xsd" located in the META-INF directory in the
> webservice archive file myService.aar.
> I would like to read this file "mySchema.xsd" in my webservice class.
> How to access it at runtime?
>
> Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-user-help@axis.apache.org
>
>



-- 
http://blogs.deepal.org

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org