views:

124

answers:

2

Hello,

I am trying to find my java class URL in order to use it in a SWT.Browser component. My goal is to display a page located in the same folder as my .java file.

If anyone knows how to do it or has a better solution to display a local page in a SWT.Browser I would be glad to know it to ;p

Thanks in advance.

+1  A: 

You can get the page's URL directly by using Class.getResource().

Michael Borgwardt
You are somehow a life saver ...
Ar3s
+2  A: 

This sounds like you want to access some resource in the classpath. This works as follows:

this.getClass().getResource("/classpath/to/resource/file");

That returns an URL, that directs to your resource. To address resources in classpath the string must start with a /. If your java-class is in the package example.package and your file (for example expample.file) is in the same directory, then the path will be: /example/package/example.file

Mnementh
Thanks for the adding, with all this I should be able to handle my problem ^^
Ar3s
I may be mistaken, but I thought that for resources in the same package as a class, you do not need any path information at all, i.e. just this.getClass().getResource("page.html"); The full path info is only needed if you use ClassLoader.getResource()
Michael Borgwardt
You may be right, but I cannot test this at the moment. If it is as you say, the call would be reduce to this.getClass().getResource("file");
Mnementh