是否将外部JavaScript库添加到Eclipse Project? [英] Adding external JavaScript library to Eclipse Project?

查看:63
本文介绍了是否将外部JavaScript库添加到Eclipse Project?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将外部JavaScript库添加到Eclipse项目时,我应该添加.js文件(d3.v2.js),还是从Github中提取压缩包的主文件?

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

Google告诉我Google.随后的Google提醒我需要Google.

Google tells me to Google it. Subsequent Googles remind me of the need to Google it.

目录树:

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

从foo.html到d3.v2.js的相对路径应为:"../d3/d3.v2.js"

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

  • 但是,也许不是.我不知道.
  • 每当我从foo.html引用d3.v2.js时,都不会发生任何事情.没什么好说的,我的意思是说浏览器中没有任何视觉上的暗示d3.js的存在.

要将d3.v2.js添加到Eclipse中,我采取了以下步骤:

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

  1. Foo->新建-> JavaScript源文件->高级->链接到文件系统中的文件->/home/tyler/workspace/foo/d3/d3.v2.js

  1. Foo -> New -> JavaScript Source File -> Advanced -> Link to File in Filesystem -> /home/tyler/workspace/foo/d3/d3.v2.js

尝试了5条不同的路径.它们都不起作用(您必须使用相对绝对值吗?)

Tried 5 different paths. None of them worked (do you have to use relative, absolute?)

  • src ="/home/tyler/workspace/Foo/d3/d3.v2.js"
  • src ="../d3/d3.v2.js"
  • src ="/Foo/d3/d3.v2.js"
  • src ="d3.v2.js"

因此,我在Eclipse中删除了对d3.v2.js的引用,并尝试将其添加为库.

So, I deleted the reference to d3.v2.js in Eclipse and attempted to add as a library.

Foo-> JavaScript资源->添加JavaScript库->用户库-配置用户库->新建->"D3"->添加.js文件-> d3.v2.js(位置:/home/tyler/workspace/Snotra/d3

Foo -> JavaScript Resources -> Add JavaScript Library -> User Library - Configure User Libraries -> New -> "D3" -> Add .js file -> d3.v2.js (location: /home/tyler/workspace/Snotra/d3

尝试了一堆路径.

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

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

  1. 冲洗,重复.

有什么想法吗?我知道这确实很容易,但是我只是不了解向Eclipse添加JavaScript库的基础.

Any ideas? I know that this is really easy, but I just don't understand the fundamentals 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");作品.

document.write("test"); works.

d3.js代码没有.

The d3.js code doesn't.

所以(也许):

  • 相对路径必须关闭(或者我必须使用绝对路径)
  • Tomcat6无法正确提供JavaScript(由于人为错误)
  • 由于人为错误,Eclipse无法正确提供JavaScript

推荐答案

Eclipse部署到Tomcat的是 WebContent 中的内容.如果您的JS文件不在WebContent中,则它们将不属于已部署的Web应用程序.

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

您需要了解Eclipse向您展示的是您的开发源文件夹.部署的不是此文件夹,而是符合Java EE规范的目录结构:

You need to understand that what Eclipse shows you is you development, source folders. What is deployed is not this folder, but a directory structure conforming the Java EE specs:

  • WebContent中的所有内容都是已部署档案的一部分
  • Java源文件已编译并存储在已部署档案的WEB-INF/类中
  • 将源目录下的非Java文件复制到已部署档案的WEB-INF/类中
  • 所有其他文件都不属于已部署档案的一部分.

这篇关于是否将外部JavaScript库添加到Eclipse Project?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆