tags:

views:

46

answers:

2

I have a jee-web-application and for using my project with oc4j application server it must be patched in my build-lifecycle to avoid several issues. Actually i do this via maven-antrun-plugin which works great. I have to remove, copy some special libraries into WEB-INF/lib and edit the web.xml, to avoid clashes with EL functions and classloading issues.

According to the maven lifecycle phases i chosed the phase prepare-package: this phase is executed before the war file is packaged, but unfortunately also before the (re-)sources are copied into the temporary working dir. I dislike working on the source folders because they're under version control and i don't want to have my coworkers to accidently commit them in cause the build-tool modified them.

So maven copies all the (re-)source stuff to target/__finalName__ where i want to fix the project for the use with oc4j. because this folder is temporary and will be packaged into the war file. Unfortunately the copying and packaging is isolated done in lifecycle package.

So how can i get between the copying of the sources and resources and the real packaging?

Example with prepare-package


This example doesn't work because the ${project.build.directory}/${build.finalName} doesn't exists and the ojdbc14.jar wasn't copied there in this phase.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.4</version>
  <executions>
    <execution>
      <id>patch-oc4j</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <tasks>
         <echo>Patching distribution for OC4J</echo>
         <echo>Deleting the obsolete OJDBC library</echo>
         <delete file="${project.build.directory}/${build.finalName}
                       /WEB-INF/lib/ojdbc14.jar" />
         [... more patching ...]
        </tasks>
      </configuration>
    </execution>
  </executions>
</plugin>
A: 

I have to remove, copy some special libraries into WEB-INF/lib and edit the web.xml, to avoid clashes with EL functions and classloading issues.

Sounds like you could, in part at least, do this with Build Profiles instead.. Your motivation for the problem above is a bit short, but if you elaborate we can judge this better..

Tim
@Tim: Thanks for your response, the webapp can be deployed in a tomcat or in a oc4j app-server. Your idea to use build profiles is great but doesn't solve my main problem how to edit/remove several files. e.g.: the oc4j has it's own `ojdbc14.jar` so we need to remove them, also the web.xml needs a few changes for this appserver. I don't know how to achieve these things.
codedevour
If you exclude the `ojdbc14.jar` by using a profile there is no need to delete it afterwards.
splash
+1  A: 

Couldn't you use a profile for this? Maybe something like this:

<profiles>
  <profile>
    <id>oc4j</id>
    <dependencies>
      <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.4.0</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
  </profile>
</profiles>
splash
Does this overrides the `<scope>compile</scope>` of the default configuration? Whats about modifying the `web.xml`? I could provide a `web-oc4j.xml` but this means i have to mantain two `web.xml` files so i have an extension point in the web.xml where i add several `context-params`
codedevour
Yes, this should override the default configuration.
splash
How would you handle a different `web.xml` file via profiles?
codedevour
It depends. ;-) I think would use 2 different files if there are many or major differences. If there is only a minor difference I would try to solve this with the `Resources plugin` and filtering. Understood both approaches in combination with profiles.
splash