简体   繁体   English

以跨平台方式启动Java应用程序

[英]launching java applications in a cross platform way

I have a Java program, let's say it's called MyApp.jar 我有一个Java程序,假设它叫做MyApp.jar

To run it on Linux, I just write a shell script called myapp.sh, which simply runs java -jar MyApp.jar and double click on it. 要在Linux上运行它,我只需编写一个名为myapp.sh的外壳脚本,该脚本只需运行java -jar MyApp.jar并双击它即可。 Everything works well. 一切正常。

On Windows 7, I cannot assume that the java command will be in everyone's path (if that's what you call it on Windows), so I have to have a workaround and do something like create a batch script with this in it: "C:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe" -jar MyApp.jar , which is obviously a Bad Solution... and it doesn't work on XP or Vista. 在Windows 7上,我不能假定java命令会出现在每个人的路径中(如果您在Windows上称呼它),因此我必须有一种解决方法,并要做一些类似的操作,在其中创建一个批处理脚本: "C:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe" -jar MyApp.jar ,这显然是一个错误的解决方案...并且在XP或Vista上不起作用。 It works on most Windows 7 machines though. 尽管它可以在大多数 Windows 7计算机上使用。

My application ships as a .zip file, the user extracts it to a folder MyApp, and then ideally will double click on something to invoke the program. 我的应用程序以.zip文件形式提供,用户将其解压缩到MyApp文件夹中,然后理想情况下将双击某些东西来调用该程序。 So far it has a .sh script for Linux users to double click on, and a batch script for Windows 7 users (it works in most cases). 到目前为止,它有一个供Linux用户双击的.sh脚本,以及一个供Windows 7用户使用的批处理脚本(在大多数情况下有效)。 It creates and consumes files in its own directory (MyApp). 它在自己的目录(MyApp)中创建和使用文件。

What is the best way to invoke this program in a cross platform way? 以跨平台方式调用该程序的最佳方法是什么?

Thanks! 谢谢!

As mentioned by biziclop, Java Web Start is commonly used to install/launch/update Java desktop apps. 如biziclop所述, Java Web Start通常用于安装/启动/更新Java桌面应用程序。

As far as the JRE goes, it is usually sufficient to use the deployJava.js linked from that page above to ensure minimum necessary JRE is installed, and the elements in the JNLP file to specify any JRE micro-versions that are supported for the app. 就JRE而言,通常使用上面页面上链接的deployJava.js足以确保安装了最低必需的JRE,并且JNLP文件中的元素可以指定该应用程序支持的任何JRE微版本。 。

Application launch 应用启动

JWS can install desktop shortcuts and menu items when supported by the OS. 如果操作系统支持,JWS可以安装桌面快捷方式和菜单项。 Those can be specified in the launch file, or added/removed at run-time using services of the JNLP API. 这些可以在启动文件中指定,也可以在运行时使用JNLP API的服务添加/删除。

Java application require a java runtime environment with a certain version to be installed on the target system. Java应用程序需要在目标系统上安装具有特定版本的Java运行时环境。

The most convenient way, to my opinion, is to ship all libraries and documentation in a single archive and add start scripts for windows and *nix systems. 我认为,最方便的方法是将所有库和文档存放在单个存档中,并为Windows和* nix系统添加启动脚本。

You could ship a JRE with your application too but then you'd have to support builds for different platforms... 您也可以在应用程序中附带JRE,但是随后您必须支持针对不同平台的构建...

If you can't deliver Java with your application, it might be a good solution to use JAVA_HOME to start it. 如果无法随应用程序一起交付Java,则使用JAVA_HOME启动它可能是一个很好的解决方案。 It is set on, well... not all but many systems. 它已启动,好吧...不是所有系统,而是所有系统。 Definitly you should not use C:\\Program Files (x86)... it is much better to use the environment variable %ProgramFiles% 绝对不要使用C:\\ Program Files(x86)...最好使用环境变量%ProgramFiles%

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

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