繁体   English   中英

NetBeans和类似Eclipse的“运行配置”

[英]NetBeans and Eclipse-like “run configurations”

是否有可能在NetBeans中创建类似于Eclipse的“运行配置”的任何内容? 我正在开发一个庞大的项目,目前没有分成Eclipse中的任何子项目。 实际上,项目中有许多应用程序具有自己的主方法和单独的类路径。 我知道,这是一团糟。

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

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

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

在Maven中使用Profiles接近Eclipse提供的Run Configuirations,但不太灵活。 因此,您可以在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>

然后在Project Properties中单击Run。 您的配置文件将列在配置的下拉菜单中: 您可以在此处为POM中列出的每个配置文件创建参数。

在此输入图像描述

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

[编辑] :所以我几乎在上面得到了答案。 单击“ 自定义...”按钮,您现在可以选择

对此IDE实例保持私有

在此输入图像描述 现在这个配置文件/配置不会存储在POM中。 实际上它存储在Project Files - nb-configuration.xml中。

在此输入图像描述

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

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

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

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

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

暂无
暂无

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

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