3

To create an Eclipse plugin, I need to import/use some resources into a stylesheet. All the necessary files reside into the plugin package and are correctly build with no errors into the final .jar.

I have this folder/files in plugin package:

> my.plugin.package.name
    > META-INF/
        > MANIFEST.MF
    > resources/
        > css/
            > base-stylesheet.css
            > win-stylesheet.css
            > linux-stylesheet.css
            > ...
        > images/
            > mytexture.png
            > ...
    > plugin.xml
    > ...

in win-stylesheet.css I want to import base-stylesheet.css and use mytexture.png, so into the CSS I do:

@import url("base-stylesheet.css");
#elemId {
    background-image: url(../images/mytexture.png);
}

unfortunately, these gives a MalformedURLException, I noticed also that:

  • using character " or ' or nothing to delimit the url string give the same error;
  • using @import url("/base-stylesheet.css") or @import url("./base-stylesheet.css") works perfecly when running/debugging the plugin into a second Eclipse instance but silently fails with the same error when the plugin jar is installed in Eclipse;
  • using @import url("platform:/plugin/my.plugin.id/resources/css/base-stylesheet.css") or @import url("platform://plugin/my.plugin.id/resources/css/base-stylesheet.css") where my.plugin.id is the Bundle-SymbolicName assigned in MANIFEST.MF give the same error both when running/debugging the plugin and when using it after installing the jar.

I suspect that the workspace directory is automatically assigned to platform:/plugin/org.eclipse.platform/.

How can I solve it?

5
  • Is this for Eclipse 4.3 (Kepler) product CSS styling or is it some other use of CSS?
    – greg-449
    Dec 8, 2013 at 15:49
  • yes it's for Eclipse 4.2+ styling Dec 8, 2013 at 16:03
  • Problem is still unsolved, is it possible that Eclipse has a such basic bug or something is missing? Dec 9, 2013 at 20:47
  • 1
    I have been trying to find any bug reports for this but without success.
    – greg-449
    Dec 9, 2013 at 21:08
  • thanks @greg-449, I searched a lot for some documentation about it but I've found nothing useful to solve it. If none will know how to solve, I'll try to add a bug report to Eclipse.. Dec 9, 2013 at 22:21

2 Answers 2

2

The existing Eclipse stylesheets just use

@import url("base-stylesheet.css");

for css in the same directory.

For resources you specify the location in the applicationCSSResources property in the product extension point properties:

<extension
     id="product"
     point="org.eclipse.core.runtime.products">
  <product
        name="%product.name"
        application="org.eclipse.e4.ui.workbench.swt.E4Application">
      <property
           name="applicationCSSResources"
           value="platform:/plugin/my.plugin.package.name/images/">
      </property>
5
  • @import url("base-stylesheet.css") gives the error when the 'import' is executed, as written in the question, I tried also without the semicolon. Dec 8, 2013 at 16:40
  • Sorry should have semicolon, edited answer. It doesn't have any leading / or ./
    – greg-449
    Dec 8, 2013 at 16:45
  • Importing in this way gives the MalformedURLException, I don't know if it's supposed to be the right behavior or it's a platform bug, have you same basic running example? Dec 8, 2013 at 16:50
  • I'm testing using a pure e4 application. Do you have a applicationCSS or cssTheme property in the product properties?
    – greg-449
    Dec 8, 2013 at 17:08
  • My manifest is very similar to this , there is no <product> property, stylesheets are declared into the <theme> properties. Dec 8, 2013 at 20:33
2

The blog post "Import CSS files in Eclipse Luna M6" from Lars Vogel seems to imply that the import now works, meaning you need at least an Eclipse 4.4 Luna M6.

Not only that 4.4 M6 release comes with a dark theme for the IDE, it also lists:

CSS includes

CSS files for Eclipse can now include other CSS files via the @import url("platform:/plugin/Bundle-Symbolic-Name/path/file.extension"); statement.
This allows easy reuse of existing style sheets.

For instance (Vogel's post):

In your RCP application, create a /css/default.css file with only one instruction:

@import url(“platform:/plugin/org.eclipse.ui.themes/css/e4-dark.css”);

Add org.eclipse.ui.themes to your RCP product and add the applicationCSS property pointing to platform:/plugin/test/css/default.css in your product extension point.

1
  • This sorted out my particular problem, which turned out to that CSS styling was working fine from the IDE but not from the (Tycho) built product. CSS file load was failing as @import was using file:// protocol and silently throwing an exception as doesn't work when accessing inside a jar. platform URI saved the day!
    – Justin
    Dec 22, 2016 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.