How to read a owl file inside a jar

4 messages Options
Embed this post
Permalink
Vivek Anandan

How to read a owl file inside a jar

Reply Threaded More More options
Print post
Permalink
Dear  all,
Suppose if i have a file named file.owl inside a jar
I could not establish the following line to read the owl file
FileReader owlFile = new FileReader("file.owl"); 
Awaiting for the solution from the group.
Thank you.
--
Regards,
Vivekanandan Ramachandran.

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Thomas Russ

Re: How to read a owl file inside a jar

Reply Threaded More More options
Print post
Permalink

On Jun 24, 2009, at 11:03 AM, Vivek Anandan wrote:

> Dear  all,
> Suppose if i have a file named file.owl inside a jar
> I could not establish the following line to read the owl file
> FileReader owlFile = new FileReader("file.owl");
> Awaiting for the solution from the group.

These are all ideas that I haven't actually tried, but they may help  
you out

1.  You could try using a jar URL for the owl file.
     http://www.exampledepot.com/egs/java.net/JarUrl.html

2. You could use the Java Resource mechanism to get an input stream to  
the owl file.
    http://lj4newbies.blogspot.com/2008/03/using-classgetresource-load-resource.html 
 
_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Ronald Cornet

Re: How to read a owl file inside a jar

Reply Threaded More More options
Print post
Permalink
If you package the owl-file with the jar in which your project resides, you can try something like below.

Ronald



(this code is from the "MyModel" class, hence the reference to that in the 3rd line).

          try {
          // first try loading the model from the JAR
            InputStream istream = MyModel.class.getResourceAsStream(fname);
            // if this fails, try loading the model from a common file
            try {
               if (istream == null) {
                 System.out.println("Not loadable from JAR, trying regular file");
                 istream = new FileInputStream(fname);
               } else {
                  System.out.println("Loading " + fname + " from JAR");
               }
            } catch(Exception e) {
               // maybe the file name it is an URI
               System.out.println("File not loadable, trying file name as URL.");
               if(istream == null) {
                  istream = new URL(fname).openStream();
               }
            }

                // if loading has failed, return
                if (istream == null) {
                        System.out.println("Unable to load model: " + fname);
                        return null;
                }


###############################################################
Ronald Cornet, PhD                    email: [hidden email]
dept. of Medical Informatics          phone: +31 (0)20 566 5188
Academic Medical Center, Room J1B-115 fax:   +31 (0)20 691 9840
P.O.Box 22700                         www: http://kik.amc.uva.nl/home/rcornet/
1100 DE  Amsterdam
The Netherlands                       'The truth is out there'
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf
> Of Thomas Russ
> Sent: Wednesday, June 24, 2009 19:11
> To: User support for the Protege-OWL editor
> Subject: Re: [protege-owl] How to read a owl file inside a jar
>
>
> On Jun 24, 2009, at 11:03 AM, Vivek Anandan wrote:
>
> > Dear  all,
> > Suppose if i have a file named file.owl inside a jar I could not
> > establish the following line to read the owl file
> FileReader owlFile =
> > new FileReader("file.owl"); Awaiting for the solution from
> the group.
>
> These are all ideas that I haven't actually tried, but they
> may help you out
>
> 1.  You could try using a jar URL for the owl file.
>      http://www.exampledepot.com/egs/java.net/JarUrl.html
>
> 2. You could use the Java Resource mechanism to get an input
> stream to the owl file.
>    
> http://lj4newbies.blogspot.com/2008/03/using-classgetresource-
> load-resource.html
>  
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03
>
>

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Vivek Anandan

Re: How to read a owl file inside a jar

Reply Threaded More More options
Print post
Permalink
Dear Thomas and Cornet Thanks for the solution

On Wed, Jul 1, 2009 at 12:41 PM, Ronald Cornet <[hidden email]> wrote:
If you package the owl-file with the jar in which your project resides, you can try something like below.

Ronald



(this code is from the "MyModel" class, hence the reference to that in the 3rd line).

         try {
                       // first try loading the model from the JAR
           InputStream istream = MyModel.class.getResourceAsStream(fname);
           // if this fails, try loading the model from a common file
           try {
              if (istream == null) {
                System.out.println("Not loadable from JAR, trying regular file");
                istream = new FileInputStream(fname);
              } else {
                 System.out.println("Loading " + fname + " from JAR");
              }
           } catch(Exception e) {
              // maybe the file name it is an URI
              System.out.println("File not loadable, trying file name as URL.");
              if(istream == null) {
                 istream = new URL(fname).openStream();
              }
           }

               // if loading has failed, return
               if (istream == null) {
                       System.out.println("Unable to load model: " + fname);
                       return null;
               }


###############################################################
Ronald Cornet, PhD                    email: [hidden email]
dept. of Medical Informatics          phone: +31 (0)20 566 5188
Academic Medical Center, Room J1B-115 fax:   +31 (0)20 691 9840
P.O.Box 22700                         www: http://kik.amc.uva.nl/home/rcornet/
1100 DE  Amsterdam
The Netherlands                       'The truth is out there'


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf
> Of Thomas Russ
> Sent: Wednesday, June 24, 2009 19:11
> To: User support for the Protege-OWL editor
> Subject: Re: [protege-owl] How to read a owl file inside a jar
>
>
> On Jun 24, 2009, at 11:03 AM, Vivek Anandan wrote:
>
> > Dear  all,
> > Suppose if i have a file named file.owl inside a jar I could not
> > establish the following line to read the owl file
> FileReader owlFile =
> > new FileReader("file.owl"); Awaiting for the solution from
> the group.
>
> These are all ideas that I haven't actually tried, but they
> may help you out
>
> 1.  You could try using a jar URL for the owl file.
>      http://www.exampledepot.com/egs/java.net/JarUrl.html
>
> 2. You could use the Java Resource mechanism to get an input
> stream to the owl file.
>
> http://lj4newbies.blogspot.com/2008/03/using-classgetresource-
> load-resource.html
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03
>
>

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03



--
Regards,
Vivekanandan Ramachandran.

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03