如何在“真实世界”中部署Java应用程序? [英] How are Java applications deployed in the "real world"?

查看:166
本文介绍了如何在“真实世界”中部署Java应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为Java编程世界的新手,这个问题一直困扰着我。我首先相信所有Java文件都被压缩到小程序然后运行,但我很快就意识到情况并非如此。有人可以向我解释我们如何将我们的Java应用程序交织成日常生活的真实产品吗?

As a novice to the world of Java programming, this question has always boggled my mind. I first believed that all Java files were compacted into applets and then ran, but I soon realized that this isn't always the case. Could someone explain to me how we actually interweave our Java applications into a real product of everyday life?

TL; DR:我们如何实现我们的代码以供实际使用?

TL;DR: How do we implement our code for practical usage?

推荐答案

这取决于应用程序。根据您希望用户使用您的应用的方式,有很多选项。通常它被打包成罐子或专用罐子(战争,耳朵)。

It depends on the application. There are many options depending on how you want your users to use your app. Usually it's packaged as a jar or a specialized jar (war, ear).

理论上,您可以使用 .class 文件压缩原始目录结构并提供shell脚本/为用户运行 java 命令的指令。我不推荐这个,因为它有点不专业,需要你为每个想要能够运行程序的操作系统维护一个shell脚本。

In theory, you could zip the raw directory structure with your .class files in it and provide a shell script/instructions that run the java command for the user. I don't recommend this because it's kind of unprofessional and requires you to maintain a shell script for each OS you want to be able to run the program on.

Jar文件用于打包库但你也可以在其中有一个清单文件,上面写着当有人双击/执行此操作时,运行此类。该类可以启动GUI或者是响应参数的无头任务等。

Jar files are used to package libraries but you can also have a manifest file in it that says, "When someone double clicks/executes this, run this class". That class can start up a GUI or be a headless task that responds to the parameters, etc.

你可以拥有 applets ,就像你说的那样。这些程序在用户的浏览器中运行。

You can have applets, like you said. These programs are run in the user's browser.

您可以拥有战争档案,这是一种打包Web应用程序的方法。您将此提供给Web服务器,它知道如何部署它以便您可以访问Web页面。示例Web服务器/容器是 tomcat 码头

You can have a war file, which is a way to package a web application. You give this to a web server and it knows how to deploy it so that you can visit the web pages. An example web server/container is tomcat or jetty.

您可以拥有之前的文件,其中可以包含其他war文件。这用于需要javaee功能的其他部分(ejbs,jms队列等)的应用程序。应用程序服务器的一个示例是 jboss 或< a href =https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&sqi=2&ved= 0CCsQFjAA&安培; URL = HTTP://glassfish.java.net/& EI = VXySUaauL8eRiQK5vYHADA&安培; USG = AFQjCNEZ2XezuzgorYJHdL-GTLFLnjPOfA&安培; SIG2 = xveESBqHhXJPI8WUwzyAIA&安培; BVM = bv.46471029,d.cGE> glassfish的。

You can have an ear file which can contain other war files inside it. This is used for applications that need other parts of the javaee functionality (ejbs, jms queues, etc.). An example of an application server is jboss or glassfish.

还有 java web start 应用程序。这些是您可以通过访问网页运行的应用程序,但它们会下载到您的计算机并在用户的计算机上运行(而不是在服务器的后端,如在战争/耳朵中)。

There's also java web start apps. These are apps you can run by visiting a webpage, but they get downloaded to your computer and run on the user's computer (instead of on the server's backend, like in a war/ear).

还有 javafx 。我对此一无所知。 通过浏览常见问题解答,它似乎是Java对Adobe的Flex 。您可以使用xml配置配置UI组件。我不确定JavaFX应用程序使用的格式,但确实说在桌面或浏览器中部署。

There's also javafx. I don't know anything about that though. By skimming the FAQ, it appears to be Java's answer to Adobe's Flex. You configure UI components with an xml configuration. I'm not sure what format JavaFX apps use, but it does say, "Deploy on the desktop or in the browser".

正如Sotirios Delimanolis在下面的评论中提到的,您可以使用Ant或Maven等构建系统构建这些文件。您还可以使用java / javaee sdk附带的工具手动构建它们。例如,如果安装了sdk,则路径中应该有一个 jar 命令。以下是这些构建系统的一些细节:

As Sotirios Delimanolis mentioned in a comment below, you can build these files with build systems like Ant or Maven. You can also build them "by hand" with the tools that come with the java/javaee sdk. For example, you should have a jar command in your path if you installed the sdk. Here are some details of these build systems:


  • Maven
  • Maven

  1. 高级别(你告诉它要构建什么,而不是如何构建它。)

  2. 不仅仅是构建系统。它还有依赖管理等。

  3. 意见(它使用约定优于配置,每个配置文件生成1个工件等)


  • Ant

  • Ant


    1. 低级别(你告诉它如何建造东西)

    2. 灵活
    3. li>
    4. 配置文件可以随心所欲,根据需要构建任意数量的工件

    5. 易于学习

    1. Low level (you tell it how to build things)
    2. Flexible
    3. Config files can do whatever you want, build as many artifacts as you want
    4. Easy to learn


  • SDK工具

  • SDK tools


    1. 始终保持最新状态。 EG:很少,maven / ant可能无法设置配置选项

    2. 难以记住命令

    3. 非常低级别

    4. 单独使用,不可重复(EG:除非你构建一个脚本,否则每次都必须自己输入jar命令)

    1. Always up to date. EG: Very rarely, maven/ant may not be able to set a configuration option
    2. Difficult to remember commands
    3. Very low level
    4. By itself, not repeatable (EG: unless you build a script, you will have to type the jar command yourself each time)


  • 这篇关于如何在“真实世界”中部署Java应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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