简体   繁体   English

打开...一个java程序

[英]Open With… a java program

I want to know how to make a java program that can be used to open stuff up. 我想知道如何制作一个可以用来打开东西的java程序。 Ex: notepad++, win zip.... Do I have convert the jar to .exe first? 例如:notepad ++,win zip ....我是否先将jar转换为.exe Also, does the file chosen get passed in to String[] args ? 此外,选择的文件是否传递给String[] args

By the way, I know that it works with cmd but thats not what I'm asking. 顺便说一句,我知道它适用于cmd,但那不是我要问的。

Depends on the OS. 取决于操作系统。 Under windows, you need to attach some details into the registry. 在Windows下,您需要将一些详细信息附加到注册表中。

Have a look at the 3rd answer in Utilising a file association in a Java application for an example? 有关示例,请参阅在Java应用程序使用文件关联中的第3个答案吗?

You could also have a look at http://www.rgagnon.com/javadetails/java-0592.html 您还可以查看http://www.rgagnon.com/javadetails/java-0592.html

UPDATE UPDATE

Also, when the OS executes the program, you should receive the file as a command line parameter through the main method 此外,当OS执行程序时,您应该通过main方法接收该文件作为命令行参数

I don't know if this will work suit your needs or not, but you could also take a look at File association in Mac 我不知道这是否适合您的需要,但您也可以查看Mac中的文件关联

There's many choices on how to make a Java program runnable. 关于如何使Java程序可运行有很多选择。 Like you mention, the simplest choice is to use the command line. 就像你提到的,最简单的选择是使用命令行。 If you want to make it work with most OS's GUI interfaces (and the Open With dialog) the easiest choice is to make an executable jar . 如果你想让它适用于大多数操作系统的GUI界面(以及打开方式对话框),最简单的选择就是制作一个可执行的jar IDEs can make this very easy for you, in Eclipse just right-click on the project and select Export > Java > Runnable JAR file. IDE可以让您轻松实现这一点,在Eclipse中右键单击项目并选择Export> Java> Runnable JAR file。

Another excellent option is to turn your application into a Java Web Start application, which lets users easily run Java programs being served up online. 另一个很好的选择是将您的应用程序转换为Java Web Start应用程序,该应用程序允许用户轻松运行在线提供的Java程序。

Alternatively, like you mention, you could convert it into an .exe file: 或者,如您所述,您可以将其转换为.exe文件:

Deploy the app. 部署应用程序。 using Java Web Start . 使用Java Web Start

JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions.. JWS提供了许多吸引人的功能,包括但不限于启动屏幕,桌面集成, 文件关联,自动更新(包括延迟下载和程序控制更新),按平台,体系结构或Java版本,配置对本机和其他资源下载进行分区运行时环境(最小J2SE版本,运行时选项,RAM等),使用扩展轻松管理公共资源。

Here is a demo. 这是一个演示。 of the file services in which the app. 应用程序的文件服务 is associated with the file type .zzz . 与文件类型.zzz相关联。

..does it get passed via the windows file chooser? ..它通过Windows文件选择器传递?

No. It gets passed to the main as either -open filename or -print filename . 不会。它会以-open filename-print filename传递给main What the app. 什么应用程序。 does with those strings is up to it. 这些字符串取决于它。 The demo. 演示。 linked above will prompt the user in the sand-boxed version, simply because it is sand-boxed. 上面链接的将提示用户使用沙盒装版本,因为它是沙盒装的。 The other one should work without showing prompt or dialog. 另一个应该没有显示提示或对话框。

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

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