UFO ET IT

실행 가능한 Java 프로그램을 어떻게 만듭니 까?

ufoet 2021. 1. 14. 07:51
반응형

실행 가능한 Java 프로그램을 어떻게 만듭니 까?


이 질문에 이미 답변이 있습니다.

JCreator에서 Java 프로그램을 프로그래밍했는데 모든 것이 완료되었지만 실행 파일을 만들고 싶습니다. 즉, Java 클래스를로드하고 컴파일 한 다음 실행하여 프로그램을 실행하고 싶지는 않지만 대신 독립 실행 형 실행 파일.

이를 수행하는 가장 빠른 방법은 무엇입니까?


SDK와 함께 번들로 제공되는 jar 도구를 사용 하여 프로그램의 실행 가능한 버전을 만들 수 있습니다.

이것이 완료되는 방법입니다.

더 쉽기 때문에 명령 프롬프트에서 결과를 게시하고 있지만 JCreator를 사용할 때도 동일하게 적용되어야합니다.

먼저 프로그램을 만듭니다.

$cat HelloWorldSwing.java
    package start;

    import javax.swing.*;

    public class HelloWorldSwing {
        public static void main(String[] args) {
            //Create and set up the window.
            JFrame frame = new JFrame("HelloWorldSwing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JLabel label = new JLabel("Hello World");
            frame.add(label);

            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    }
    class Dummy {
        // just to have another thing to pack in the jar
    }

매우 간단합니다. "Hello World"가있는 창만 표시합니다.

그런 다음 컴파일하십시오.

$javac -d . HelloWorldSwing.java

"start"폴더 Dummy.classHelloWorldSwing.class 내에 두 개의 파일이 생성되었습니다 .

$ls start/
Dummy.class     HelloWorldSwing.class

다음 단계로 jar 파일을 만듭니다. 각 jar 파일에는 실행 파일과 관련된 속성이있는 매니페스트 파일이 있습니다.

이것은 내 매니페스트 파일의 내용입니다.

$cat manifest.mf
Main-class: start.HelloWorldSwing

메인 클래스가 무엇인지 설명하십시오 (public static void main 메서드를 사용하는 클래스)

매니페스트가 준비되면 jar 실행 파일이 호출됩니다.

여기에는 -c -m -f (-c to create jar, -m to specify the manifest file, -f = the file should be named ..) and the folder I want to jar.

$jar -cmf manifest.mf hello.jar start

그러면 시스템에 .jar 파일이 생성됩니다.

여기에 이미지 설명 입력

나중에 해당 파일을 두 번 클릭하면 예상대로 실행됩니다.

여기에 이미지 설명 입력

JCreator에서 .jar 파일을 만들려면 "Tools"메뉴를 사용하고 jar를 만들어야하지만 매니페스트가 어떻게 거기에 있는지 잘 모르겠습니다.

내가 찾은 비디오는 다음과 같습니다. Create a Jar File in Jcreator .

이 ".jar"접근 방식에 익숙해지면이 스레드에 게시 된 다른 링크를 계속 진행할 수 있다고 생각합니다.

jnlp (Java Network Launcher Protocol) 도 사용할 수 있습니다 .


Eclipse를 사용하는 경우 아래 7 단계를 시도하여 Windows 용 .exe 파일을 얻을 수 있습니다.

1 단계2 단계step3

이제 JAR 파일이 있습니다. java -jar path / jarname.jar을 사용하여 실행하십시오.

여기에 이미지 설명 입력


이것을 .exe로 변환하려면 http://sourceforge.net/projects/launch4j/files/launch4j-3/ 를 시도 하십시오.

5 단계6 단계

STEP7: Give the .xml file an appropriate name and click "Save". The .xml file is standard, don't worry about it. Your executable file will now be created!


I'm not quite sure what you mean.

But I assume you mean either 1 of 2 things.

  • You want to create an executable .jar file

Eclipse can do this really easily File --> Export and create a jar and select the appropriate Main-Class and it'll generate the .jar for you. In windows you may have to associate .jar with the java runtime. aka Hold shift down, Right Click "open with" browse to your jvm and associate it with javaw.exe

  • create an actual .exe file then you need to use an extra library like

http://jsmooth.sourceforge.net/ or http://launch4j.sourceforge.net/ will create a native .exe stub with a nice icon that will essentially bootstrap your app. They even figure out if your customer hasn't got a JVM installed and prompt you to get one.


On the command line, navigate to the root directory of the Java files you wish to make executable.

Use this command:

jar -cvf [name of jar file] [name of directory with Java files]

This will create a directory called META-INF in the jar archive. In this META-INF there is a file called MANIFEST.MF, open this file in a text editor and add the following line:

Main-Class: [fully qualified name of your main class]

then use this command:

java -jar [name of jar file]

and your program will run :)


Take a look at WinRun4J. It's windows only but that's because unix has executable scripts that look (to the user) like bins. You can also easily modify WinRun4J to compile on unix.

It does require a config file, but again, recompile it with hard-coded options and it works like a config-less exe.


Jexecutable can create Windows exe for Java programs. It embeds the jars into exe file and you can run it like a Windows program.


You could use GCJ to compile your Java program into native code.
At some time they even compiled Eclipse into a native version.


Write a script and make it executable. The script should look like what you'd normally use at the command line:

java YourClass

This assumes you've already compiled your .java files and that the java can find your .class files. If java cannot find your .class files, you may want to look at using the -classpath option or setting your CLASSPATH environment variable.


Take a look at launch4j


Java Web Start is a good technology for installing Java rich clients off the internet direct to the end user's desktop (whether the OS is Windows, Mac or *nix). It comes complete with desktop integration and automatic updates, among many other goodies.

For more information on JWS, see the JWS info page.


As suggested earlier too, you can look at launch4j to create the executable for your JAR file. Also, there is something called "JExePack" that can put an .exe wrapper around your jar file so that you can redistribute it (note: the client would anyways need a JRE to run the program on his pc) Exes created with GCJ will not have this dependency but the process is a little more involved.


NetBeans를 사용하는 경우 f11을 누르면 프로젝트가 빌드됩니다. 기본 경로는 projectfolder \ dist입니다.

참조 URL : https://stackoverflow.com/questions/804466/how-do-i-create-executable-java-program

반응형