10

Is it possible to create anything similar to Eclipse's "run configurations" in NetBeans? I am working on a huge project which is currently not divided into any subprojects in 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. 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. Is this possible?

If it's easy to emulate this behaviour with "external" projects, hints about that are welcome as well.

auramo
  • 13,167
  • 13
  • 66
  • 88

3 Answers3

4

Don't know if this is of any interests a lot months later: http://wiki.netbeans.org/FaqTwoMainClassesWithArguments

Karussell
  • 17,085
  • 16
  • 97
  • 197
3

Using Profiles in Maven is close to the Run Configuirations that Eclipse provides but not quite as flexible. So you can define your profile in your 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. 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.

enter image description here

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. 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. 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.

[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

enter image description here and now this profile/configuration will NOT be stored in the POM. In fact it is stored in the Project Files - nb-configuration.xml.

enter image description here

Nelda.techspiress
  • 643
  • 12
  • 32
1

What I would do is use Ant and have a bunch of targets that invoke the main() methods you are intrerested in.

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.

Note that NetBeans allows you to define even toolbar / menu shortcuts to Ant targets of your choosing, I find that very useful.

For example my project build files typically have shortcuts to even start and stop Tomcat, see this for an example:

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Proposed solution assumes use of ant when most projects have moved on to maven or gradle. – Farrukh Najmi Dec 21 '15 at 13:50
  • 1
    There is even a plugin available, Run with Arguments, but again it is Ant based. Looking for that feature that is agnostic of the build tool being used. http://plugins.netbeans.org/plugin/53855/run-with-arguments – Nelda.techspiress Feb 03 '17 at 16:45