Java 如何在 Eclipse IDE 的 Apache Tomcat 服务器中部署创建的 .jar 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29843130/
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-11 08:40:41  来源:igfitidea点击:

How to deploy created .jar file in Apache Tomcat server in Eclipse IDE?

javaeclipsetomcatjar

提问by mindfreak

I'm stuck into the process of deploying created .jar files in Eclipse.

我陷入了在 Eclipse 中部署创建的 .jar 文件的过程。

Eclipse is at location: E:\eclipse

Eclipse 位于: E:\eclipse

Web project is at: E:\Runtime_Testing\src\study_to_night

Web 项目位于: E:\Runtime_Testing\src\study_to_night

Tomcat is at location: C:\apache-tomcat-7.0.54-windows-x64

Tomcat 位于: C:\apache-tomcat-7.0.54-windows-x64

Meanwhile, steps followed for creating jar files in Eclipse:

同时,在 Eclipse 中创建 jar 文件的步骤如下:

  1. Right click on your Java Project and select Export.
  2. Expand the Java node and select JAR file.
  3. In the JAR File Specificationpage, checked the option which says "Export Java source files and resources"
  4. Selected the export destination as: E:OneForAll.jar; OneForAllbeing the name of my .jar file
  5. Checked the option` "Compress the contents of the JAR Files"
  6. Next ---> Finish.
  1. 右键单击您的 Java 项目并选择导出。
  2. 展开 Java 节点并选择 JAR 文件。
  3. JAR 文件规范页面中,选中“导出 Java 源文件和资源”选项
  4. 选择出口目的地为:E:OneForAll.jar; OneForAll我的 .jar 文件名称
  5. 选中“压缩 JAR 文件的内容”选项
  6. 下一步 ---> 完成。

On following the above steps, an executable JARfile is created at the specified location. Just to check if all the files have been extracted in the .jar component, when I chose "Extract files"option, all source files were traceable. However, on double-click it throws Error: Invalid or corrupt jarfile 'E:OneForAll.jar'.

执行上述步骤后,将JAR在指定位置创建一个可执行文件。只是为了检查 .jar 组件中是否已提取所有文件,当我选择“提取文件”选项时,所有源文件都是可追踪的。但是,双击它会抛出Error: Invalid or corrupt jarfile 'E:OneForAll.jar'.

I feel I'm lost. Is there something I missed out? What went wrong?

我觉得我迷路了。有什么我错过了吗?什么地方出了错?

Could someone walk me through the steps to do this manually ?

有人可以引导我完成手动执行此操作的步骤吗?

采纳答案by MichaelStoner

So you have it running successfully within eclipse? But now you want to deploy this tested web app?

所以你在eclipse中成功运行了吗?但是现在您想部署这个经过测试的 Web 应用程序吗?

Then

然后

  1. Right click on your Java Project and select Export.

  2. Expand the Web node and select WAR file.

  1. 右键单击您的 Java 项目并选择导出。

  2. 展开 Web 节点并选择 WAR 文件。

This exports the WEB-INF and related files that tomcat needs.

这将导出 tomcat 需要的 WEB-INF 和相关文件。

This question answers what to do next How to deploy a war file in Tomcat 7

此问题回答接下来要做什么How to deploy a war file in Tomcat 7

回答by sunny

Apache tomcat is a web container you cannot deploy a jar in tomcat server. If you created a web application then export your application as war file and put it in tomcat webapp directory, start the server and your war will be deployed.

Apache tomcat 是一个 web 容器,你不能在 tomcat 服务器中部署 jar。如果您创建了一个 web 应用程序,然后将您的应用程序导出为 war 文件并将其放在 tomcat webapp 目录中,启动服务器,您的 war 将被部署。

if you have lots of jars then still you need to bundle them as war

如果你有很多罐子,那么你仍然需要将它们作为战争捆绑在一起