【问题标题】:NetBeans and Eclipse-like "run configurations"NetBeans 和类似 Eclipse 的“运行配置”
【发布时间】:2009-08-12 19:26:35
【问题描述】:

是否可以在 NetBeans 中创建类似于 Eclipse 的“运行配置”的任何东西?我正在做一个巨大的项目,目前在 Eclipse 中没有分成任何子项目。事实上,项目中有很多应用程序都有自己的主要方法和单独的类路径。我知道,这是一团糟。

我正在考虑将项目迁移到 NetBeans。从长远来看,创建许多项目是明智的,但现在如果我可以在 NetBeans 中做与在 Eclipse 中类似的事情,那将是一个真正的救命稻草:创建具有自己的类路径的“启动器”。这可能吗?

如果使用“外部”项目很容易模拟这种行为,那么也欢迎提供相关提示。

【问题讨论】:

    标签: java eclipse netbeans


    【解决方案1】:

    不知道几个月后这是否有任何兴趣:http://wiki.netbeans.org/FaqTwoMainClassesWithArguments

    【讨论】:

      【解决方案2】:

      在 Maven 中使用配置文件类似于 Eclipse 提供的运行配置,但不够灵活。所以你可以在你的 POM.xml 中定义你的配置文件

      <profiles>
          <profile>
              <id>Config1</id>
              <build>
                  <plugins>
                      <plugin>
                          <!-- create an all-in-one executable jar with maven-shade-plugin bound 
                              to phase:package special handling for spring.handlers/spring.schemas files 
                              to prevent overwriting (maven-shade-plugin joins them to one file) usage: 
                              cd to <project>/target java -jar hello-world-java-1.0-executable.jar spring/batch/job/hello-world-job.xml 
                              helloWorldJob -->
                          <artifactId>maven-shade-plugin</artifactId>
                          <version>1.7</version>
                          <executions>
                              <execution>
                                  <phase>package</phase>
                                  <goals>
                                      <goal>shade</goal>
                                  </goals>
                                  <configuration>
                                      <filters>
                                          <filter>
                                              <artifact>*:*</artifact>
                                              <excludes>
                                                  <exclude>META-INF/*.SF</exclude>
                                                  <exclude>META-INF/*.DSA</exclude>
                                                  <exclude>META-INF/*.RSA</exclude>
                                              </excludes>
                                          </filter>
                                      </filters>
                                      <transformers>
                                          <!-- Added this one because of runtime exception - No container 
                                              provider supports the type class org.glassfish.grizzly.http.server.HttpHandler 
                                              see - http://stackoverflow.com/questions/9787265/grizzly-and-jersey-standalone-jar -->
                                          <transformer
                                              implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                          <transformer
                                              implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                              <mainClass>com.myCompany.nexgen.main.Start</mainClass>
                                              <!-- <mainClass>org.springframework.boot.loader.Launcher</mainClass> -->
                                          </transformer>
                                          <transformer
                                              implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                              <resource>META-INF/spring.handlers</resource>
                                          </transformer>
                                          <transformer
                                              implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                              <resource>META-INF/spring.schemas</resource>
                                          </transformer>
                                      </transformers>
                                      <shadedArtifactAttached>true</shadedArtifactAttached>
                                      <!-- configures the suffix name for the executable jar here it will 
                                          be '<project.artifact>-<project.version>-executable.jar' -->
                                      <shadedClassifierName>executable</shadedClassifierName>
                                  </configuration>
                              </execution>
                          </executions>
                      </plugin>
                  </plugins>
              </build>
          </profile>
          <profile>
              <id>myLocalrun</id>
              <build>
                  <directory>
                      c:\sdev\myDev\myProj
                  </directory>
              </build>
          </profile>
      </profiles>
      

      然后在项目属性中单击运行。您的配置文件将列在配置的下拉菜单中:。您可以在此处为 POM 中列出的每个配置文件创建参数。

      这不是问题的完整答案。显然,NetBeans 缺乏在 IDE 内快速轻松地切换运行配置以及使这些配置独立于构建工具和存储库外部的能力。我附加到不同的数据库并根据我正在处理的项目的哪个方面使用不同的输入配置。这在 NetBeans 中是非常有限的。我不希望我的所有运行配置都检查到存储库中,这是将配置文件添加到项目 POM 时会发生的情况。

      [编辑]:所以我几乎已经有了上面的答案。点击Customize...按钮,您现在可以选择

      对此 IDE 实例保持私有

      现在这个配置文件/配置将不会存储在 POM 中。事实上,它存储在项目文件 - nb-configuration.xml 中。

      【讨论】:

        【解决方案3】:

        我要做的是使用 Ant 并拥有一堆目标来调用您感兴趣的 main() 方法。

        事实上,这样做的好处是您可以使用这些,甚至可以在命令行上在 IDE 之外使用这些“快捷方式”,这对于持续集成构建和类似的事情很有用。

        请注意,NetBeans 甚至允许您为您选择的 Ant 目标定义工具栏/菜单快捷方式,我觉得这非常有用。

        例如,我的项目构建文件通常具有启动和停止 Tomcat 的快捷方式,示例如下:

        http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/

        【讨论】:

        • 当大多数项目转移到 maven 或 gradle 时,建议的解决方案假定使用 ant。
        • 甚至还有一个可用的插件,Run with Arguments,但它同样是基于 Ant 的。寻找与正在使用的构建工具无关的功能。 plugins.netbeans.org/plugin/53855/run-with-arguments
        猜你喜欢
        • 1970-01-01
        • 2015-07-25
        • 2013-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多