简体   繁体   English

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

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

Is it possible to create anything similar to Eclipse's "run configurations" in NetBeans? 是否有可能在NetBeans中创建类似于Eclipse的“运行配置”的任何内容? I am working on a huge project which is currently not divided into any subprojects in Eclipse. 我正在开发一个庞大的项目,目前没有分成Eclipse中的任何子项目。 There are in fact many applications in the project which have their own main-methods and separate classpaths. 实际上,项目中有许多应用程序具有自己的主方法和单独的类路径。 I know, it's a mess. 我知道,这是一团糟。

I'm considering about migrating the project to NetBeans. 我正在考虑将项目迁移到NetBeans。 In the long run it would be sensible to create many projects but for now it would be a real life-saver if I could do similar stuff in NetBeans than in Eclipse: create "launchers" which have their own classpaths. 从长远来看,创建许多项目是明智的,但是现在如果我可以在NetBeans中执行与Eclipse类似的东西,那将是一个真正的生命保护:创建具有自己的类路径的“启动器”。 Is this possible? 这可能吗?

If it's easy to emulate this behaviour with "external" projects, hints about that are welcome as well. 如果使用“外部”项目很容易模仿这种行为,那么也欢迎提示。

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

Using Profiles in Maven is close to the Run Configuirations that Eclipse provides but not quite as flexible. 在Maven中使用Profiles接近Eclipse提供的Run Configuirations,但不太灵活。 So you can define your profile in your POM.xml 因此,您可以在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>

Then in the Project Properties click on Run. 然后在Project Properties中单击Run。 Your profiles will be listed in the dropdown menu for Configuration:. 您的配置文件将列在配置的下拉菜单中: Here is where you can create the Arguments for each profile listed in the POM. 您可以在此处为POM中列出的每个配置文件创建参数。

在此输入图像描述

This is not a complete answer to the issue. 这不是问题的完整答案。 Clearly NetBeans is lacking in the capability to quickly and easily switch between run configurations within the IDE and have those configurations be independent of the build tool and external to the repository. 显然,NetBeans缺乏在IDE中快速轻松地在运行配置之间切换的能力,并且这些配置独立于构建工具并且在存储库外部。 I attach to different databases and use different input configurations based on which aspect of the project I'm working on. 我附加到不同的数据库,并根据我正在处理的项目的哪个方面使用不同的输入配置。 This is very limiting in NetBeans. 这在NetBeans中非常有限。 I don't want all my run configurations checked into the repository which is what will happen with the profiles being added to the project POM. 我不希望我的所有运行配置都检入存储库,这是将配置文件添加到项目POM时会发生的情况。

[EDIT] : So I was almost there with the answer above. [编辑] :所以我几乎在上面得到了答案。 Clicking on the Customize... button you can now select 单击“ 自定义...”按钮,您现在可以选择

Keep private to this IDE instance 对此IDE实例保持私有

在此输入图像描述 and now this profile/configuration will NOT be stored in the POM. 现在这个配置文件/配置不会存储在POM中。 In fact it is stored in the Project Files - nb-configuration.xml. 实际上它存储在Project Files - nb-configuration.xml中。

在此输入图像描述

What I would do is use Ant and have a bunch of targets that invoke the main() methods you are intrerested in. 我要做的是使用Ant并拥有一堆目标来调用你感兴趣的main()方法。

In fact the advantage of this is that you can use these even use these "shortcuts" outside of your IDE on the command line, useful for continuous integration builds and things like that. 实际上,这样做的好处是,您甚至可以在命令行上使用IDE之外的这些“快捷方式”,这对于持续集成构建和类似的东西非常有用。

Note that NetBeans allows you to define even toolbar / menu shortcuts to Ant targets of your choosing, I find that very useful. 请注意,NetBeans允许您甚至为您选择的Ant目标定义工具栏/菜单快捷方式,我发现它非常有用。

For example my project build files typically have shortcuts to even start and stop Tomcat, see this for an example: 例如,我的项目构建文件通常具有甚至可以启动和停止Tomcat的快捷方式,请参阅以下示例:

http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/ 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