I am using Eclipse (Helios) with the "m2eclipse" plugin. I am working on a Maven-based web application project that I am testing on a local Tomcat server that is configured inside Eclipse.
This usually works more or less great. "m2eclipse" can sometimes be flaky ... but for the most part it keeps the settings of my POM and my Eclipse project in sync, and also stores the deployed code in Tomcat.
However, recently I added a wrinkle. I have one JavaScript file that should be different when moving from a test environment to a real production environment. The differences are too significant to be handled by Maven filtering and token replacement. I needed to save two separate files in my project and use only those that are suitable for the build profile.
I accomplished this with some "targetPath" tricks in my Maven POM:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <webResources> <resource> <directory>src/main/webapp/js/${profile.name}</directory> <targetPath>js</targetPath> </resource> <resource> <directory>src/main/webapp/js</directory> <excludes> <exclude>prod</exclude> <exclude>non-prod</exclude> </excludes> </resource> </webResources> </configuration> </plugin>
This creates a perfect WAR file that works great when I deploy it to an external Tomcat server. However, the problem is that Eclipse does NOT use this WAR file when running Tomcat inside Eclipse. Instead, Eclipse works with an exploded version of the application deployed in such a hidden directory:
<workspace>/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/MyApp
... and, apparently, the application files are copied to this place. PRIOR TO Maven does the little trick shown above. Thus, when testing locally inside Eclipse, JavaScript is not present at all at the expected location.
Is there any way to solve this problem? Perhaps changing Eclipse or changing Maven to pull a file from the "target" directory from Maven to the Eclipse directory "wtpwebapps"? Maybe there is another approach to solving the problem with profile-include-include-file?
source share