如何在Eclipse中将多个Java文件导出为一个可运行的单一JAR文件?

huangapple go评论74阅读模式
英文:

How do you export multiple java files as a singular runnable jar file in Eclipse?

问题

我有一个包含3个Java文件的项目:
Title_Screen.java
Game_Screen.java
Game_Code.java

Game_Screen和Game_Code使用OpenGL,Title_Screen打开Game_Code,而Game_Code打开Game_Screen。在Eclipse中,程序运行得很好,但当我尝试将其导出为可运行的jar文件时,无论我做什么,它总是只导出Title_Screen.java。我做错了什么?我需要采取哪些步骤才能将这三个Java文件导出到一个.jar文件中?

编辑:这似乎只发生在我的程序中,也许与OpenGL库有关?

编辑2:我从程序中移除了库,将其导出为jar文件时得到了相同的结果。我的实际问题是我无法将库放入其中。

编辑3:问题解决了!我所需做的只是使用jarsplice来创建可运行的jar,而不是使用Eclipse。我使用的教程:https://www.youtube.com/watch?v=YqGUk84BmlQ

英文:

I have a project with 3 java files:
Title_Screen .java
Game_Screen .java
Game_Code .java

Game_Screen and Game_Code use OpenGL, and Title_Screen opens Game_Code which opens Game_Screen. In eclipse, the program works perfectly, but when I try to export it as a runnable jar file, no matter what I do, it always just exports Title_Screen.java. What am I doing wrong, and what steps do I have to take to export all three java files in one .jar file?

Edit: It seems to only happen to my program, perhaps it's something to do with the OpenGL libraries?

Edit 2: I removed the libraries from my program, same results as exporting it to a jar file. My actual problem is that I can't put in the libraries.

Edit 3: Problem resolved! All I had to do was use jarsplice to create my runnable jar, not Eclipse. Tutorial I used: https://www.youtube.com/watch?v=YqGUk84BmlQ

答案1

得分: 1

你可以使用以下命令构建 JAR 文件,并指定主类入口点(Main)。

jar cfe output.jar Main src/Repository/* src/util/*.class

在创建 JAR 文件时,您可以写入多个文件。

jar cf Output.jar src/util/Main.class src/util/SubMain.class src/Repository/*

或者从 Eclipse 中进行操作:

将您的所有文件放入 Eclipse 项目中的一个文件夹,然后:

1.右键单击该文件夹
2.导出
3.Java -> Runnable JAR 文件
英文:

You can use the following command to build the jar and specify the main class entry point (Main).

jar cfe output.jar Main src/Repository/* src/util/*.class

you can write multiple files when creating the jar

jar cf Output.jar src/util/Main.class src/util/SubMain.class src/Repository/*

Or from eclipse

Put all your files in a folder in your Eclipse project and then:

1.Right click in your folder
2.Export
3.Java -> Runnable JAR File

答案2

得分: 0

以下是翻译好的内容:

你正在执行哪些步骤将其导出为可运行的JAR文件?
您能够成功运行JAR文件吗?

导出可运行JAR文件的步骤:

  1. 在项目上右键单击,然后选择“导出”选项。
  2. 提供目标路径,即JAR文件需要存储的位置。
  3. 导出
英文:

What steps are you following to export it as runnable jar?
Are you able to run the jar file successfully?

Steps to export Runnable jar is :

  1. Right click on project and select "Export" option.
  2. Provide the destination path where the jar file needs to be store.
  3. Export

huangapple
  • 本文由 发表于 2020年9月16日 19:01:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63918608.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定