Vaadin 7: How to import JS files from a user path?

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

I am trying to import a js file into myproject/WebContent/js/test.js I used @JavaScript in my user interface class as shown 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 the error log "NetworkError: 404 Not Found - http://localhost:8080/myproject/APP/PUBLISHED/js/test.js" in my firebug console.

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

PS: Please do not force me to manually create the APP / PUBLISHED / directory! Thanks.

+6
source share
2 answers

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 
+13
source

the file you are referencing must be accessible to the classloader relative to the package in which you use it. According to your example, your VaadinTest package is com.example.app , and you want to access it as js/test.js you have to put it in the com/example/app/js/test.js in the β€œroot” for the bootloader classes to find it (for example, src/main/java,groovy or where resources are loaded from your configuration).

+2
source

Source: https://habr.com/ru/post/972302/


All Articles