使 Java 程序在线可供所有人使用
我刚刚用 Java 编写了一个程序。我很好奇是否可以在线下载该程序,以便我的朋友和家人可以利用它。不知道从哪里开始。
我希望它在本地运行。只需双击 .class 文件,我就可以在计算机上本地运行该程序,我还可以创建 .class 文件的快捷方式并直接从桌面运行它。有没有办法将 .java 文件与 .class 文件(有 4 个 .class 文件)一起压缩并通过电子邮件发送给我希望使用它的人?我尝试将包含 zip 文件的电子邮件发送到家里的另一台计算机,但 .class 文件无法在另一台计算机上运行该程序......还有其他方法可以实现这种情况吗?
有什么建议吗?
I have just written a program in Java. I am curious if I can make the program downloadable online so that my friends and family can take advantage of it. No clue where to even begin.
I would like it to run locally. I am able to run the program locally on my computer by simply double clicking the .class file, I also can create a shortcut to the .class file and run it directly from my desktop. Is there a way to zip the .java file along with the .class files (there are 4 .class files) and email that to those that I wish to use it? I tried to send an email with the zip file to another computer in the house, but the .class file wouldn't run the program on the other computer...is there another way to make this happen?
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
看一下 Java Web Start:
Have a look at Java Web Start:
为什么不直接将 *.jar 文件上传到网络服务器并让您的朋友从那里下载它呢?
如果你想将程序嵌入到网页中,你应该编写一个java applet。
why don't you simply upload your *.jar file to a web server and let your friends download it from there?
if you want the program to be embedded in a web page, you should write a java applet.
您可以分发可运行的 Jar 文件本身,或者如果您有兴趣通过浏览器安装它,您也可以查看 java web start
You could distribute the runnable Jar file itself, or if you're interested in making it install via the browser you could also look into java web start
如果您创建了网络应用程序,则可以将其托管在 GAE 上,这是一种非常好的方式在线申请。如果您的应用程序是桌面 Java 应用程序,则只需将其上传到任何 FTP/HTTP 服务器上即可。
另一个解决方案是使用 java web start< /a> 样式,这将允许用户下载应用程序并直接从浏览器运行它。
资源:
同一主题:
If you created a web application you can host it on GAE, which is a really nice way to have online applications. If your application is a desktop java application, then just upload it on any FTP/HTTP server.
Another solution is to use the java web start style, which will allow the users to download the application and run it directly from the browser.
Resources :
On the same topic :
这是可能的。让我们考虑一下,[yourclass] 是主类的名称(您双击的类文件的名称),[appname] 是您想要为应用程序指定的任何名称。两者都区分大小写。
只需按照以下步骤操作:
1)创建一个名为“manifest.mft”的空白文件。
2)在manifest.mft中写入:
“清单版本:1.0
主班级:[您的班级]
类路径:.
"
3) 创建一个名为“run.bat”的空白文件
4) 在run.bat中写入:
"java -jar [appname].jar"
5) 首先需要编译 .java 文件: "javac [file].java"
6) 然后需要将所有类文件和清单文件打包在一个 jar 文件中:
"jar cvfm [appname].jar manifest.mft *.class"
7) 您现在要做的就是将 [appname].jar 和 run.bat 发送给您想要的人,他们所要做的就是双击在 run.bat 文件上运行您的程序。他们必须安装 JRE,并且 JRE 的 bin 文件夹位于 Windows PATH 系统变量中。
This is possible. Let's consider that [yourclass] is the name of the primary class (the name of the class file on which you double-click) and [appname] is whatever name you want for your application. Both are case sensitive.
Just follow the next steps:
1) make a blank file with the name "manifest.mft".
2) write in manifest.mft:
"Manifest-Version: 1.0
Main-Class: [yourclass]
Class-path: .
"
3) make a blank file named "run.bat"
4) write in run.bat:
"java -jar [appname].jar"
5) you first need to compile your .java file: "javac [file].java"
6) you then need to package all the class files and the manifest file in a jar file:
"jar cvfm [appname].jar manifest.mft *.class"
7) all you have to do now is to send the [appname].jar and run.bat to whom you want and all they got to do is to double click on the run.bat file to run your program. They must have JRE installed and the bin foder of the JRE in windows PATH system variable.
不幸的是,Java 并不是“与家人和朋友”共享应用程序的最佳语言。
基本上,如果您希望他们能够运行该程序,您首先需要创建一个 jar,并且他们需要安装 JRE,并从命令行运行它。
一个非常好的选择是使用类似 Launch4J 的东西,它将帮助您创建“本机”可执行文件,并嵌入JRE 或下载它的链接、图标、安装程序以及所有使您的程序看起来更专业、更少业余爱好的东西
Unfortunately, Java is not the best language to share an app "with family and friends".
Basically, if you want them to be able to run the program, you first need to create a jar, and they need to have the JRE installed, and run it from command line.
A really good option is to use something like Launch4J which will help you create "native" executables, with an embedded JRE or a link to download it, an icon, an installer, and all that stuff that make your program look more professional and less hobby-like