Java 将 tomcat jar/lib 目录添加到 Mac OS X 上的 eclipse 类路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19460236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:25:56  来源:igfitidea点击:

Add tomcat jar/lib directory to eclipse classpath on Mac OS X

javaeclipsemacostomcat

提问by helion3

I have a project that requires some Tomcat libs to run properly. I installed Tomcat (on Mac) which is essentially just a put-the-folder-somewhere process. I originally resolved the issue by adding the needed jar files as external jars for the project - however this messes with the project .classpathwhich I can't allow - those changes would be tracked in our source control.

我有一个项目需要一些 Tomcat 库才能正常运行。我安装了 Tomcat(在 Mac 上),它本质上只是一个放置文件夹的过程。我最初通过将所需的 jar 文件添加为项目的外部 jar 来解决该问题 - 但是这会与.classpath我不允许的项目混淆- 这些更改将在我们的源代码管理中进行跟踪。

I've tried adding the tomcat/libdirectory to eclipse as a classpath variablebut that doesn't resolve the issue.

我已经尝试将该tomcat/lib目录作为类路径变量添加到 eclipse 中,但这并没有解决问题。

When the tomcat server starts, I receive ClassNotFoundException: HttpServletRequest.

当 tomcat 服务器启动时,我收到ClassNotFoundException: HttpServletRequest.

How else can I add the tomcat lib directory so that I'm not modifying the project classpath?

我还能如何添加 tomcat lib 目录,以便我不会修改项目类路径?

回答by mo sean

basically i am using windows i dont know about that, but you can do that from eclipse right click on your project in eclipse then see there is a build path from that import(some thing like that) server's(tomcat) lib file where you have install server and put all libs file if you want all

基本上我正在使用我不知道的 Windows,但是您可以从 eclipse 中执行此操作,在 eclipse 中右键单击您的项目,然后查看该导入(类似的东西)服务器的(tomcat)lib 文件中的构建路径。如果需要,安装服务器并放置所有库文件

回答by ug_

I use sysdeo tomcat plugin found at http://www.eclipsetotale.com/tomcatPlugin.html. You can also install it by going to Help->Eclipse Marketplace->search for sysdeo

我使用http://www.eclipsetotale.com/tomcatPlugin.html 上的sysdeo tomcat 插件。您也可以通过转到 Help->Eclipse Marketplace->search for sysdeo 来安装它

What it does is add a menu item called tomcat in your options that allows you to add projects to tomcat classpath and add tomcat libs to your project pre-compile.

它的作用是在您的选项中添加一个名为 tomcat 的菜单项,允许您将项目添加到 tomcat 类路径并将 tomcat 库添加到您的项目预编译中。

Heres some screenshots of it.

这是它的一些屏幕截图。

starting and stopping tomcat is made easier: enter image description here

启动和停止 tomcat 变得更容易: 在此处输入图片说明

and where you can add the libs to classpath (and much more)

以及在哪里可以将库添加到类路径(以及更多)

enter image description here

在此处输入图片说明

回答by wang

Maybe you can create an user library which include the jars in the tomcat/lib, then add the user library in your java projet by those steps :

也许您可以创建一个用户库,其中包含 tomcat/lib 中的 jar,然后通过以下步骤在您的 java 项目中添加用户库:

Build Path > Configure Build Path > Libraries > Add library > Add user library

构建路径>配置构建路径>库>添加库>添加用户库

回答by gamerson

You can install Webtools plugin (installed by default in Eclipse for JavaEE Developers) and then you will get Tomcat runtime support. Then you can add a "Tomcat Runtime" to your project and it will automatically include all Tomcat jars that are available to webapps running on Tomcat.

您可以安装 Webtools 插件(默认安装在 Eclipse for JavaEE Developers 中),然后您将获得 Tomcat 运行时支持。然后你可以在你的项目中添加一个“Tomcat 运行时”,它会自动包含所有可用于在 Tomcat 上运行的 web 应用程序的 Tomcat jar。

  1. Window > Preferences > Server > Runtime environments
  2. Add..
  3. Select Tomcat version
  4. Browse to tomcat install dir
  5. Right click you project > Properties
  6. Select Java Build Path
  7. Add library... > Server Runtime > select your runtime you created
  1. Window > Preferences > Server > Runtime environments
  2. 添加..
  3. 选择Tomcat版本
  4. 浏览到 tomcat 安装目录
  5. 右键单击您的项目 > 属性
  6. 选择 Java 构建路径
  7. 添加库... > 服务器运行时 > select your runtime you created

This process will also modify your .classpathfile but it will do so in a way that is easy to share with other developers.

此过程还将修改您的.classpath文件,但它会以易于与其他开发人员共享的方式进行。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by Vikrant Goel

I've had this problem several times while using subversion with windows users. The Tomcat directory will have servlet-api.jar. Copy and paste it in your eclipse project, right click and add to build path.

在与 Windows 用户一起使用 subversion 时,我多次遇到此问题。Tomcat 目录将包含servlet-api.jar. 将其复制并粘贴到您的 eclipse 项目中,右键单击并添加到构建路径。

Now you don't want to commit the classpath. Then simply deselect .classpathfile while committing.

现在您不想提交类路径。然后只需.classpath在提交时取消选择文件。