Cataclysm
Cataclysm

Reputation: 8568

Vaadin 7 : How to import JS files from custom path?

I am using Vaadin-7 and this answer was not fix for me .

I am trying to import my js file under myproject/WebContent/js/test.js . I used @JavaScript in my UI class as below..

@Theme("myTheme")
@SuppressWarnings("serial")
@Title("VaadinTest")
@JavaScript("js/test.js")
public class VaadinTest extends UI {

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
}
}

But I got "NetworkError: 404 Not Found - http://localhost:8080/myproject/APP/PUBLISHED/js/test.js" error log in my firebug console.

So , how can I import js files from my custom directories ?

PS: Please don't be force me to create APP/PUBLISHED/ directory manually ! Thanks.

Upvotes: 7

Views: 6003

Answers (2)

cfrick
cfrick

Reputation: 37008

the file you refer to must be reachable by the classloader relative to the package you are using it in. according to your example, lets say your package of VaadinTest is com.example.app and you want to access it as js/test.js you have to put it in the directory com/example/app/js/test.js in a "root" for the classloader to find it (e.g. src/main/java,groovy or where resources are loaded from in your config).

Upvotes: 3

Zigac
Zigac

Reputation: 1601

You can use app://:

@JavaScript({ "app://js/test.js" })

or use:

@JavaScript({ "vaadin://js/test.js" })

Generated url inside VAADIN folder:

http://localhost:8080/myproject/VAADIN/js/test.js

Upvotes: 15

Related Questions