简体   繁体   English

如何使用快捷方式像典型程序一样运行Java应用程序?

[英]How do I run a java application like I would a typical program, using a shortcut?

I'm currently using an IDE for writing a java application and testing it. 我目前正在使用IDE编写Java应用程序并对其进行测试。 In the IDE, I can run the application and see how it works. 在IDE中,我可以运行该应用程序并查看其工作方式。 However, how would I run the application using a shortcut, or a jar file? 但是,如何使用快捷方式或jar文件运行应用程序? For example, in order to run my WAMP server, I run the wamp.exe file in the WAMP directory. 例如,为了运行我的WAMP服务器,我在WAMP目录中运行了wamp.exe文件。 So, I'm running a single file which launches the entire program. 因此,我正在运行一个文件,它将启动整个程序。 How do I achieve this sort of thing with a java application? 如何使用Java应用程序实现这种目的? I've heard about using a jar file, but I'm unsure about whether that would be the proper way to do this or not. 我听说过要使用jar文件,但是不确定这是否是正确的方法。

It depends on the IDE you are using. 这取决于您使用的IDE。 With eclipse for example, you open up the file tab, select export, open java in the tree, and select runnable jar file. 例如,使用eclipse,打开“文件”选项卡,选择“导出”,在树中打开Java,然后选择可运行的jar文件。 Then fill the interface out and your good to go. 然后填写界面,一切顺利。

If you are using Eclipse, then you can export your application as a single jar file and run it directly by double clicking 如果使用的是Eclipse,则可以将应用程序导出为单个jar文件,并通过双击直接运行它

In the Package Explorer view: 在“包资源管理器”视图中:

  1. Right click on your project 右键点击您的项目
  2. Go to "Export" 转到“导出”
  3. Click on "Export as Runnable Jar" 点击“导出为可运行的罐子”

And you are done 你完成了

And if you are using Netbeans, then follow these steps: 如果您使用的是Netbeans,请按照以下步骤操作:

  1. Right click on your project 右键点击您的项目
  2. Click on "Clean and Build" 点击“清理并构建”
  3. Now got the directory where your netbeans projects are created( usually it should be "C:\\Users\\your_user_name\\Documents\\NetBeansProjects" 现在获得了创建netbeans项目的目录(通常应为“ C:\\ Users \\您的用户名\\ Documents \\ NetBeansProjects”
  4. Open the directory of your project (directory with the name of your project name) 打开项目的目录(带有项目名称的目录)
  5. Open "dist" folder and you'll find the jar file of your application/project there. 打开“ dist”文件夹,您将在其中找到应用程序/项目的jar文件。

Java Web Start is the easiest way to add shortcuts for a desktop app. Java Web Start是添加桌面应用程序快捷方式的最简单方法。

Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. Java Web Start(JWS)是Oracle Corporation的技术,用于直接从网络或Internet链接启动富客户端(Swing,AWT,SWT)桌面应用程序。 It offers 'one click' installation for platforms that support Java. 它为支持Java的平台提供“一键式”安装。

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等),使用扩展轻松管理公共资源。

See also 也可以看看

This answer - the 2 icons on the right "JotPad" & "Star Zoom Animation" are icons installed by JWS. 这个答案 -右侧“ JotPad”和“ Star Zoom Animation”中的2个图标是JWS安装的图标。

You can also, just for fun, create a launcher in C++ that launches your executable(the way Limewire did it). 您也可以只是出于娱乐目的,用C ++创建一个启动器来启动您的可执行文件(Limewire这样做的方式)。 A simple console mode C program is given below. 下面给出了一个简单的控制台模式C程序。

#include <stdlib.h>

int main(int argc, char *argv[]) {
    system("java YourProgramClassFileNameHere");
    return 0;
}

An advanced methodology would require CreateProcess() in win32API or in JNI for your platform. 一种高级方法需要针对您的平台在win32API或JNI中使用CreateProcess()

You can convert it to an executable Jar file(See Abu's answer) 您可以将其转换为可执行的Jar文件(请参阅Abu的答案)

You can also, create a bat file which can run your program: (Windows only) 您也可以创建一个可以运行程序的bat文件:(仅Windows)

@echo off
start java YourProgramClassFileNameHere

Or a shell script(BASH) 或shell脚本(BASH)

Also, see here run a executable jar from c++ code 另外,请参阅此处从C ++代码运行可执行jar

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

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