简体   繁体   English

更改打开jar时首先运行哪个Java文件

[英]Changing which java file runs first when opening jar

I'm not entirely sure how to word this but how would I go about changing which java file in my package is the first one to open when the compiled jar file is executed? 我不完全确定该如何措辞,但是当执行已编译的jar文件时,如何更改包中的哪个Java文件是第一个打开的java文件呢?

I'm also using netbeans if that helps. 如果有帮助,我也会使用netbeans。

You can changed it in Netbeans. 您可以在Netbeans中进行更改。 When you run the whole project in netbeans, the first class that is executed there is also the first class to be executed in the jar file built by Netbeans. 当您在netbeans中运行整个项目时,执行的第一个类也将在Netbeans构建的jar文件中执行第一个类。

You can right click your project in the project window and select Properties. 您可以在项目窗口中右键单击您的项目,然后选择属性。 From the window that opens, select the run category in the left side. 在打开的窗口中,选择左侧的运行类别。 Then on the right side, there is a button to browse and select the file for the Main Class. 然后在右侧,有一个按钮浏览并选择Main Class的文件。

The manifest indicates the Main-Class that runs when you execute a jar file. 清单指示执行jar文件时运行的Main-Class。

https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

If you have two (or more) classes with public static void main , click File | 如果您有两个(或多个)具有public static void main ,请单击File | Project properties and in the Categories dialog, click Run and look for Main Class: . Project properties然后在“ Categories对话框中,单击Run ,然后查找“ Main Class: and then click Browse... to select which main class to start with. 然后单击“ Browse...以选择要开始的主类。

(But I'm not sure this answers what you really want to do since once compiled with the chosen main class, there's no way to later have the .jar file run another class. If this doesn't answer your question, maybe a good question in return is, "What are you trying to do?") (但是我不确定这是否会回答您真正想做的事情,因为一旦使用选定的主类进行编译,就无法再使.jar文件运行另一个类。如果这不能回答您的问题,也许是一个不错的选择。回报的问题是:“您要做什么?”)

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

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