Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipse + Maven + Tomcat: testing web apps when the WAR is built with custom options
    primarykey
    data
    text
    <p>I am using Eclipse (Helios), with the "m2eclipse" plugin. I am working on a Maven-based web application project, which I test on a local Tomcat server that is setup inside Eclipse.</p> <p>Generally, this works more or less great. "m2eclipse" can sometimes be flaky... but for the most part it keeps my POM and my Eclipse project settings in sync, and likewise keeps the deployed code current in Tomcat.</p> <p>However, recently I've added a wrinkle. I have one JavaScript include file that needs to be different when going from the test environment to the real production environment. The differences are too significant to be cleanly handled by Maven filtering and token substitution. What I needed was to keep two separate files in my project, and only deploy the one appropriate for the build profile.</p> <p>I accomplished this with some "targetPath" trickery in my Maven POM:</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt; &lt;version&gt;2.1.1&lt;/version&gt; &lt;configuration&gt; &lt;webResources&gt; &lt;resource&gt; &lt;!-- take the stuff from a "prod" or "non-prod" subdirectory and copy it one level up --&gt; &lt;directory&gt;src/main/webapp/js/${profile.name}&lt;/directory&gt; &lt;targetPath&gt;js&lt;/targetPath&gt; &lt;/resource&gt; &lt;resource&gt; &lt;!-- now don't deploy those profile-specific subdirectories --&gt; &lt;directory&gt;src/main/webapp/js&lt;/directory&gt; &lt;excludes&gt; &lt;exclude&gt;prod&lt;/exclude&gt; &lt;exclude&gt;non-prod&lt;/exclude&gt; &lt;/excludes&gt; &lt;/resource&gt; &lt;/webResources&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <p>This builds a perfect WAR file, which works fine when I deploy it some external Tomcat server. However, the problem is that Eclipse does NOT use that WAR file when running Tomcat inside of Eclipse. Instead, Eclipse works with an exploded version of the application, deployed to a cryptic directory like this:</p> <pre><code>&lt;workspace&gt;/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/MyApp </code></pre> <p>... and apparently the app's files are copied to this location PRIOR TO Maven doing the little trickery shown above. Therefore, when testing locally inside of Eclipse, no JavaScript include is present at all in the expected location.</p> <p>Is there a way around this problem? Maybe an Eclipse change, or a Maven change, to pull the file from Maven's "target" directory to Eclipse's "wtpwebapps" directory? Maybe there's another approach to solving the profile-specific-include-file issue altogether?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload