Adding an external JavaScript library to an Eclipse project?

When adding an external JavaScript library to an Eclipse project, should I add a .js file (d3.v2.js) or a tarballed wizard pulled from Github?

Google tells me about it Google. Subsequent Googles remind me of the need for Google.


Directory Tree:

. |-build |---classes |-src |-WebContent |---foo.html |---META-INF |---WEB-INF |-----lib |---d3 |-----d3.v2.js 

The relative path from foo.html to d3.v2.js should be: "../d3/d3.v2.js"

  • But maybe not. I dont know.
  • Whenever I refer to d3.v2.js from foo.html nothing happens. Nothing happens, I do not mean anything is not visually displayed in the browser, which suggests that d3.js even exists.

To add 'd3.v2.js to Eclipse, I took the following steps:

  • Foo β†’ New β†’ JavaScript source file β†’ Advanced β†’ Link to a file in the file system β†’ /home/tyler/workspace/foo/d3/d3.v2.js

  • Tried 5 different ways. None of them worked (do you need to use relative, absolute?)

    • src = "/ main / Tyler / workspace / Foo / d 3 / d3.v2.js"
    • src = "../d3/d3.v2.js"
    • src = "/Foo/d3/d3.v2.js"
    • src = "d3.v2.js"
  • So, I deleted the link to d3.v2.js in Eclipse and tried to add it as a library.

  • Foo β†’ JavaScript resources β†’ Add JavaScript library β†’ User library - Custom library settings β†’ Create β†’ β€œD3” β†’ Add .js file β†’ d3.v2.js (location: / home / Tyler / workspace / Snotra / d3

  • I tried a bunch of ways.

    • src = "d3.v2.js"
    • src = "../d3/d3.v2.js"
    • src = "/Foo/d3/d3.v2.js"

      • Rinse, repeat.

Any ideas? I know this is very simple, but I just don’t understand the basics of adding JavaScript libraries to Eclipse.

foo.html

 <!DOCTYPE HTML> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8" /> <title>Tyler J. Fisher</title> <link rel="stylesheet" href="master.css" /> <script type="text/javascript" src="../d3/d3.v2.js"></script> </head> <body> <section id="foo_view"> <script type="text/javascript"> document.write("test"); <!--Works--> var dataset[1,2,3,4,5]; d3.select("body").selectAll("p") <!--Doesn't work--> .data(dataset) .enter() .append("p") .text("RABBLE"); </script> </section> </body> </html> 

document.write ("test"); works.

The d3.js code does not work.

So (maybe):

  • The relative path should be turned off (or maybe I should use absolute paths)
  • Tomcat6 does not serve JavaScript properly (due to human error)
  • Eclipse does not serve JavaScript properly (due to human error)
+4
source share
1 answer

What Eclipse deploys to Tomcat is what is inside WebContent . If your JS files are not in WebContent, they will not be part of the deployed web application.

You need to understand what Eclipse shows you - these are your designs, source folders. What is being deployed is not this folder, but a directory structure that complies with Java EE specifications:

  • Everything in WebContent is part of a deployed archive
  • Java source files compiled and stored in WEB-INF / Deployed Archive Classes
  • Files other than Java in the source directory are copied to the WEB-INF / Deployed Archive classes.
  • All other files are not part of the deployed archive.
+6
source

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


All Articles