简体   繁体   English

我可以在 Tomcat 上运行 .jar 文件吗?

[英]Can I run .jar file on Tomcat?

a very noob question.一个非常菜鸟的问题。 Can I run a .jar file on Tomcat.我可以在 Tomcat 上运行 .jar 文件吗? I am not building a web-app.我不是在构建网络应用程序。 I simply need to run a .jar with say HalloWorld in it.我只需要运行一个包含 HalloWorld 的 .jar 文件。 Is this possible/appropriate.这可能/合适吗?

Thanks谢谢

You can run a Java archive without Tomcat, simply with a Java Runtime Environment:您可以在没有 Tomcat 的情况下运行 Java 存档,只需使用 Java 运行时环境:

$ java -jar myhelloworldapp.jar

Tomcat is a servlet container, only needed for web applications. Tomcat 是一个 servlet 容器,只有 web 应用程序需要。

I don't really know what your use case is, but what you probably need is a virtual private server (VPS) provider.我真的不知道您的用例是什么,但您可能需要的是虚拟专用服务器 (VPS) 提供商。 They give you a virtual host which runs OS of your choice and you can install JVM on it.他们为您提供了一个运行您选择的操作系统的虚拟主机,您可以在其上安装 JVM。 There are many VPS' available.有许多 VPS 可用。 Try Linode or Slicehost.尝试 Linode 或 Slicehost。

It would help if you would explain what you are trying to achieve, then we might be able to give you a better answer.如果您能解释一下您要实现的目标,那将会有所帮助,然后我们或许可以为您提供更好的答案。

我想你想要的是 Java 的webstart

It sounds like want you want to do is deploy batch code to your server and then run it.听起来您想要做的是将批处理代码部署到您的服务器然后运行它。 You could either create a new web-app that contains your jar, or add the jar to an existing web app.您可以创建一个包含您的 jar 的新 web 应用程序,或者将 jar 添加到现有的 web 应用程序中。 Then you can trigger execution with a servlet.然后您可以使用 servlet 触发执行。 You could even have a JSP that contains:您甚至可以拥有一个包含以下内容的 JSP:

<%
  String [] args = new String[0];
  MyClass.main(args);
%>

Of course you'd want to secure that JSP so that not just anyone can run your job.当然,您希望保护该 JSP,以便不是任何人都可以运行您的工作。

We use the quartz scheduler to schedule batch jobs from within tomcat.我们使用石英调度程序从 tomcat 中调度批处理作业。 This let's us monitor our jobs much more easily than if they were run from the command line.与从命令行运行相比,这让我们可以更轻松地监控我们的作业。

http://www.quartz-scheduler.org/ http://www.quartz-scheduler.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM