0

I'm developing a project in Eclipse with SWT, where the interface is shown in a browser and for that, I use the XULRunner (Firefox) instead of using the standard browser.

I thought to compile the jar with the xurlrunner folder inside, so I created a source folder called "plugins" and copied the xurlrunner folder inside and got the path:

URL xulrunner = getClass().getClassLoader().getResource("xulrunner");
File file = new File(xulrunner.toURI());
System.setProperty("org.eclipse.swt.browser.DefaultType", "mozilla");
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", 
        -> file.getAbsolutePath());

It worked, but only when run from within the Eclipse before exporting, however, the big problem is that when I export for a jar executable, the JVM can not load, of course, the reason is that file.getAbsolutePath() could not point to into the jar.

For images, I use getResourceAsStream() and it works very well once compiled, but when it is to transform a folder path inside the jar to String is that it is difficult.

QUESTION:

Is there any other way I can point to a folder into the jar that can be turned to String?


PROPOSAL

if there is no a way to keep the xurlrunner folder into the jar, I'll create an installer apart to extract it from a zip to the same location of the program installation and dynamically point to it.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Suzerain
  • 49
  • 4
  • You may benefit from checking out these two questions: http://stackoverflow.com/questions/36182101/exported-jar-file-wont-read-file-inside-jar | http://stackoverflow.com/questions/36269693/unable-to-locate-open-image-inside-exported-jar – Keno Apr 13 '16 at 15:55
  • @KenoClayton System.setProperty() only accepts String, how can I pass "InputStream getResourceAsStream" to it – Suzerain Apr 13 '16 at 16:20
  • http://stackoverflow.com/questions/3891375/how-to-read-a-text-file-resource-into-java-unit-test – Keno Apr 13 '16 at 16:24
  • Use `IOUtils.toString()` – Keno Apr 13 '16 at 16:24
  • @KenoClayton Scanner instead of IOUtils.toString, Scanner scanner = new Scanner(InputStream); scanner.useDelimiter("\\A"); String str = scanner.hasNext() ? scanner.next() : null; but is not my case, thank u so much, I think the way is extract xurlrunner into my program installation path and point to it. – Suzerain Apr 13 '16 at 16:48

1 Answers1

0

SWT expects the XULRunnerPath to point to a regular filesystem folder. Thefore the entire xulrunner folder must be extracted into a regular folder before setting the system property.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79