2

We have 2 Maven applications, a war application which contains our jsps and presentation layer code, and a shared library which contains our business layer code.

Before migrating to maven we had the shared library as a project reference of the WAR application. Whenever we built or debugged the WAR application in Netbeans, the shared library would get automatically compiled and built and any new changes were picked up automatically.

With Maven, it looks like any time we make a change to the shared library we now need to build the shared library project BEFORE debugging. Is there any way to retain the efficiency of the old method?

When we debug the WAR application is there any way to have Maven build the shared library dependency (local jar project) automatically whenever we debug?

Jerry B
  • 135
  • 1
  • 9

3 Answers3

0

In eclipse its just a matter of the auto build/hot deploy set up correctly. Just make sure to have maven plugin installed and use it as the the builder for the project.

I don't imagine netbeans is much different.

Community
  • 1
  • 1
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • Changes to the jsps are being picked up with no problem. What I need Netbeans to do is to trigger a build of the shared library anytime a build of the WAR application is triggered. – Jerry B Jun 28 '12 at 16:04
  • Why ? It has not changed so why bother ? And if it has changed but is not updating, your build path is not correct. – NimChimpsky Jun 28 '12 at 16:14
  • For example if I change a method signature in the shared library from getWidget() to getWidgetOne() the jsp's in the WAR file will not pick it up unless I build the shared library, then debug the WAR project. I need the war project to package the shared library's jar automatically whenever it is built. – Jerry B Jun 28 '12 at 16:17
  • In eclipse you would just add the dependent project to the build path of war project.And remove any other reference to the the code (ie the compiled jar file) in the auto build path. This is ide specific its not anythign to do with maven – NimChimpsky Jun 28 '12 at 16:22
  • Does eclipse automatically build the jar whenever you make a change to a source file? If not, how does the new jar get generated? – Jerry B Jun 28 '12 at 16:26
  • yes it does autobuild - what else would it do. But that is not to say the war file is referencing the autobuilt jar. I think. – NimChimpsky Jun 28 '12 at 16:26
  • Anyway my point is, yes eclipse, and imagine netbeans will be able to do what you want with a bit of config. – NimChimpsky Jun 28 '12 at 16:32
  • Yeah I'm sure there's a way, just can't figure it out for the life of me. – Jerry B Jun 28 '12 at 16:37
0

Ok, I finally accomplished this using the maven invoker plugin:

<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.6</version>
<configuration>
    <projectsDirectory>../</projectsDirectory>
    <pomIncludes>
        <pomInclude>project1/pom.xml</pomInclude>
        <pomInclude>project2/pom.xml</pomInclude>
    </pomIncludes>
    <goals>
        <goal>install</goal>
    </goals>
</configuration>
<executions>
    <execution>
        <id>build-deps</id>
        <goals>
            <goal>install</goal>
        </goals>
    </execution>
</executions>

I highly doubt this is best practice, but it got the job done. You could install this into it's own profile to make sure it doesn't interfere with automated building.

Jerry B
  • 135
  • 1
  • 9
0

The way that I've worked around this is to have a parent POM that encapsulates all of the sub-components:

myProject
 +- myProject-web
 +- myProject-bl
 +- myProject-da
 \- myProject-domain

Each is a separate project that builds into it's own maven dependency. Then, the parent POM simply includes the other projects:

<modules>
  <module>myProject-web</module>
  <module>myProject-bl</module>
  <module>myProject-da</module>
  <module>myProject-domain</module>
</modules>

Now, whenever you build myProject, maven will rebuild the sub-components if they are out of date. Since maven builds each sub-component individually, you will have each part in your Maven repo, accessible by any other project that needs to use one or more parts of your project.

RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55
  • Yeah that's definitely the right way of doing it. But that adds another project, and another build to the development process in Netbeans. For example if I make a small change in myProject-da, then I have to build myProject and then debug myProject-web (which Netbeans will build too). I know an extra step isn't a big deal, but when making many small changes it adds up. – Jerry B Jun 29 '12 at 23:40
  • Isn't that what you're doing now? You build your business logic (since it changed) and then you debug your JSP bundle. That seems like the same amount of steps to me.... Am I missing something? – RustyTheBoyRobot Jun 30 '12 at 01:06