简体   繁体   English

使用NetBeans Maven项目运行多个类

[英]Run multiple classes with netbeans maven project

I have one Maven project in Netbeans, which has several classes, which contain a main method. 我在Netbeans中有一个Maven项目,该项目有几个类,其中包含一个主要方法。

Is there a way to run different classes with a shortcut? 有没有办法用快捷方式运行不同的类? I mean something like the different run configurations in Eclipse, which offers me a dropdown. 我的意思是像Eclipse中不同的运行配置一样,它提供了一个下拉菜单。

I found out that I can specify different main classes, if I add several configurations in NetBeans. 我发现,如果在NetBeans中添加几个配置,则可以指定不同的主类。 But for me it is not very convenient if I have to set the configuration to A and press run, set the configuration to B and press run and so on. 但是对我来说,如果必须将配置设置为A并按Run,将配置设置为B并按Run等,并不是很方便。

Well this doesn't actually answers the question in the manner you want but this could be one of the workaround solution. 好吧,这实际上并不能以您想要的方式回答问题,但这可能是解决方法之一。

  1. Create a separate class having a main method. 创建一个具有main方法的单独的类。
  2. It has a main method that calls main function of each of the classes (you want to run) using Switch-Case. 它具有main方法,该方法使用Switch-Case调用每个类(要运行)的main函数。
  3. Put this switch case in a loop with an exit switch. 将此开关盒与出口开关循环放置。

link to achieve step 3. Using switch statements inside a for loop 链接以实现步骤3。 在for循环内使用switch语句

Note: Visibility of classes can be an issue. 注意:类的可见性可能是一个问题。

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

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