简体   繁体   English

在Linux系统上部署Java项目

[英]Deploying a Java project on Linux system

I developed a project using Java and now I've to deliver it to client who is using Linux. 我使用Java开发了一个项目,现在我将它提供给使用Linux的客户端。 Which executable file format will be delivered and how to make that? 将交付哪种可执行文件格式以及如何制作?

Executable file format? 可执行文件格式?

If you're delivering a Java app, give them a jar file (and associated libs). 如果您要提供Java应用程序,请为它们提供一个jar文件(以及相关的库)。

Provide a shell script to set up its environment and execute it. 提供shell脚本来设置其环境并执行它。

For example, assuming I define ROOT_DIR as my app's install directory, and so on: 例如,假设我将ROOT_DIR定义为我的应用程序的安装目录,依此类推:

CLASSPATH="${ADD_JARS}:${CLASSPATH}:${ROOT_DIR}/lib/myApp.jar:\
${ROOT_DIR}/lib/jibx/jibx-run.jar:\
${ROOT_DIR}/lib/jibx/xpp3.jar:\
${ROOT_DIR}/lib/bindings.jar:\
${ROOT_DIR}/lib/commons-lang-2.0.jar:\
${ROOT_DIR}/lib/forms-1.0.5.jar"
"${JAVACMD}" -Xmx256M -DanyDefsNeeded=foobar -Dbase.dir="${ROOT_DIR}" -cp "${CLASSPATH}" myApp.main.Launcher "$@"

What goes into the shell script depends totally on what your app actually needs to start up. shell脚本的内容完全取决于您的应用实际需要启动的内容。

A jar. 一个罐子。 If it is not executable, then a script (.sh) to launch the jar. 如果它不可执行,则使用脚本(.sh)启动jar。

Well basically what you wanna put in a .sh file is the commands you'd normally type at the console to run your jar file. 基本上你想放在.sh文件中的是你通常在控制台上键入的命令来运行你的jar文件。 They should be separated by a new line (ie each on a separate line in the .sh file). 它们应该用新行分隔(即每个行都在.sh文件中的一行中)。

The most basic you can go is add something like this to your sh file: 你可以去的最基本的东西是你的sh文件:

java -Xms=64m -Xmx=256m -jar myJar.jar -classpath [dependencies dir]/dep1.jar,[dependencies dir]/dep2.jar

beyond this you can do more exotic stuff, like parametrise some environment variables, get command line argumens from when the .sh is launched and pass them to the jar executatble etc. Look up "bash scripting" for advanced stuff: 除此之外,你可以做更多奇特的事情,比如参数化一些环境变量,从.sh启动时获取命令行参数并将它们传递给jar可执行文件等。查看高级内容的“bash脚本”:

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-2.html#ss2.1 http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-2.html#ss2.1

You might have better luck using Launch4J , IzPack or other installer that has cross-platform capabilities. 使用Launch4JIzPack或其他具有跨平台功能的安装程序可能会更好。 This might be a better first option than trying to understand the intricacies and idiosyncrasies of the different Linux distributions and shells. 这可能是比尝试理解不同Linux发行版和shell的复杂性和特性更好的第一选择。

If your app. 如果你的应用程序 has a GUI, the best user experience for installation/deployment can be had by way of Java Web Start . 有一个GUI,可以通过Java Web Start获得最佳的安装/部署用户体验。 Note that JWS can deploy apps. 请注意,JWS可以部署应用程序。 to Windows, *nix and Mac. 到Windows,* nix Mac。 and avoids all the maintenance woes of generating 3 separate (platform specific) executables. 并避免产生3个独立(特定于平台)可执行文件的所有维护困难。

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

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