如何为 Windows 创建独立的 Java 可执行文件?
我对 Java 编程很陌生,我不知道它是如何工作的,但我确实有一些 PHP、Javascript、Pascal 和一些 C++ 的经验。
我一整天都在搜索 Java 编程教程,发现了一些有趣的教程,但只涉及基础知识。我不想创建控制台程序并了解变量和循环。
我需要一个教程来展示如何用 Java 创建一个程序,该程序可以打开一个带有一些选项卡和多个可单击按钮的窗口。以 .exe 文件(而不是 .class)启动的程序,并且包含大量 .jar 文件。
I'm very new to Java programming, and I don't know how it works, but I do have some experience with PHP, Javascript, Pascal and some C++.
I've searched all day for Java programming tutorials and I've found some interesting tutorials but only about the basics. I don't want to create console programs and to learn about variables and loops.
I need a tutorial that shows me how to create a program in Java, something that opens a window with some tabs and multiple clickable buttons. A program that starts with a .exe file, not a .class and what contains lots of .jar files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
听起来你想用Java 编写一个GUI 程序。看看 Java Swing。谷歌提供了大量资源,以下是一个:
http://zetcode.com/tutorials/javaswingtutorial/< /a>
It sounds like you want to write a GUI program using Java. Have a look at Java Swing. There are a ton of resources available via google, here's one:
http://zetcode.com/tutorials/javaswingtutorial/
您需要使用 JNI 从 C/C++ 程序内部启动 JVM。
这是一个示例。
启动 JVM 后,只要您通过了如果参数正确,您应该会看到 JVM 引导 Java 代码并从您的 main 方法开始。
You need to use JNI to launch a JVM internally from a C / C++ program.
Here's an example.
Once you have the JVM up, provided you passed the correct parameters to it, you should see the JVM bootstrap the Java code and start from your main method.
该文件名为
java.exe
?但认真地说:您可以在网上找到所谓的包装脚本,它几乎可以做您想要的事情。您可能还想看看:http://jnc.mtsystems.ch/
The file ist called
java.exe
? But in earnest: You can find so called wrapper-scripts on the net, that can do almost what you want.You also might want to take a look at: http://jnc.mtsystems.ch/
对于显示 Swing GUI 的简单程序,您不需要额外的
.jar
文件。 Java 编译为.class
文件,您可以自己将其打包为.jar
文件。您可以使用批处理文件执行此操作,或使用 Java 启动器,例如 exe4j 。For a simple program that shows a Swing GUI, you will not need additional
.jar
files. Java compiles to.class
files which you can pack to a.jar
file yourself. This you can execute with a batch file or use a Java launcher like exe4j.如果您对 Java 图形用户界面感兴趣,您应该阅读
javax.swing
包中的 Java swing 框架。至于制作标准的 Windows 可执行文件 (.exe),它有点复杂,但您可以做到。一般来说,当您想要分发程序时,您会将其转换为 .jar 文件并能够通过以下方式执行它:
您可以在 C/C++ 中创建一个简短的 .exe 来执行此行。您还可以创建一个执行相同操作的 .bat 脚本。请记住,您必须安装 Java 才能运行您的程序,因此当您将程序分发给其他人时,他们必须先安装 Java。
If you're interested in graphical user interface for Java you should read about the Java swing framework in the
javax.swing
package.As far as making a standard windows executable (.exe), it's a bit more complicated but you can do it. Generally, when you want to distribute your program you'll turn it into a .jar file and be able to execute it via:
You can create a short .exe in C/C++ that executes this line. You could also create a .bat script that does the same. Keep in mind that you must have Java installed for your program to run, so when you distribute your program to other people, they will have to install Java first.