Re: How to read script file from .jar package

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: How to read script file from .jar package

Wade Chandler-6
> Hi,all:
>     My scripts file are packaged into .jar file,how
to load >script with the source() method
>in this case? I tried with the following method but
not success.
>     URL url =
>getClass().getResource("/org/laniqi/test.script");
>     Interpreter i = new Interpreter();
>   try{
>    i.source( url.getFile() );
>   }catch(EvalError e1){
>        ... ...
>    }
>      Is there any methods to resolve this problem?
If the >source method can accept URL
>params, that will be great!
>    
>   Thanks,
>   Karl.
 
Use:
         java.io.BufferedReader brin =
            new java.io.BufferedReader(
            new
java.io.InputStreamReader(url.openStream(),"UTF-8")
            );
         Object o = i.eval(brin);

I have some methods I use which let me pass a String
and the code figures out if it's a URL and is a starts
with file: or new File(value).exists() then do source
other wise see if it's a URL and can open with new
URL(value).openStream() and use eval.  It makes it a
little more flexible.

Wade


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Re: How to read script file from .jar package

Daniel Wunsch
> Use:
>          java.io.BufferedReader brin =
>             new java.io.BufferedReader(
>             new
> java.io.InputStreamReader(url.openStream(),"UTF-8")
>             );
>          Object o = i.eval(brin);

brin.close();

daniel


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users