简体   繁体   English

如何运行(dot)java文件

[英]How to run a (dot)java file

I've been looking around for a tutorial on how to compile/run a java file. 我一直在寻找有关如何编译/运行Java文件的教程。 I know you can run it and compile it with eclipse, and you can type "javac" in terminal (mac), but i would like to send a small program i wrote to a friend, and he can just click on it to run it. 我知道您可以运行它并使用eclipse进行编译,并且可以在终端(mac)中键入“ javac”,但是我想发送一个我写给朋友的小程序,他可以单击它来运行它。 Maybe a class file, I don't know. 也许是班级档案,我不知道。 I am running mac btw. 我正在运行mac btw。

Make it a runnable jar from eclipse. 从eclipse使其成为可运行的jar。 Your main file will run. 您的主文件将运行。

A good tutorial if you need @ Create a Java exe file / executable JAR 如果您需要@ 创建Java exe文件/可执行JAR的很好的教程

HTH HTH

First of all create an executable JAR File and then- 首先创建一个可执行的JAR文件,然后-

You can create- 您可以创建-

  1. a batch file(.bat) for windows like this, 像这样的Windows批处理文件(.bat),

     @echo off start javaw -jar XYZ.jar 

    save this file to ABC.bat, now this file is executable, just double click on it and run your program. 将文件保存到ABC.bat,现在该文件是可执行文件,只需双击它即可运行程序。

  2. an executable file(.exe) for windows, like this, 像这样的Windows可执行文件(.exe),

    This is a C program- 这是一个C程序-

     ‪#‎include‬ <string.h> #include <stdlib.h> void main (int argc, char **args) { char *jarfile = "XYZ.jar"; // jar file name... int n = strlen(jarfile); char *cmd = (char *)malloc(n+50); strcpy(cmd, "startw java -jar "); strcat(cmd, jarfile); system(cmd); } 

    compile this file with any c compiler, now run the executable file(.exe). 使用任何c编译器编译该文件,现在运行可执行文件(.exe)。

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

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