K
K
kirawa2016-03-03 11:48:48
Java
kirawa, 2016-03-03 11:48:48

How to include jquery library in JavaFx?

I have a web view in which I want to connect jquery from resources. maven project. tried to connect using absolute paths in index.html file.1d6666d332984636aeb4e04d06566bd3.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kirawa, 2016-03-03
@kirawa

Let's say if I write such an absolute path, then it works, what should I do?

<script src="jar:file:/C:/Users/kirawa/Documents/NetBeansProjects/shoping-fx/target/shoping-fx-1.0-SNAPSHOT.jar!/html/jquery-ui.js"></script>

E
Evgeny Kornachev, 2016-03-03
@zelan

in general, if the html file is in a jar, then to install external styles and scripts, you need to specify the full absolute path to the files.
It is better to do this: load a file not from a jar into the webview, in which case everything will work as it should. Those. paths to scripts and styles can be specified relative (relative to index.html).
instead of a line
add

try {
      webEngine.load(new File("html/index.html").toURI().toURL().toExternalForm());
} catch (IOException e) {
      e.printStackTrace();
}

and REMOVE the html folder with the content from the resources to the same level where the src, .idea folders are located.
When you run the jar (after assembly), the html folder with the contents should lie next to it (either manually or with maven). In this case, everything will be loaded and working.
There is another option, to write a script that collects all styles and scripts when building the application and writes their contents inside index.html, for sure someone has already done this in the web world. Then your version of the program will work, since everything will be in one file and loading will not be needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question