0

Я перемещаю существующий проект (наследие) на maven. Он имеет следующую структуру:maven-resources-plugin + профили

ParentProject 
- EARModule 
    - src 
    - target 
    - pom.xml (ear) 
- WARModule 
    - src 
    - main 
     - java 
     - (java packages and classes) 
     - resources 
     - dev 
      - index.jsp 
     - prod 
      - index.jsp 
     - webapp 
     - views 
      - index.jsp (original) 
     - WEB-INF 
    - target 
    - pom.xml (war) 
- pom.xml (parent) 

Я намерен иметь два разных профиля: производство и разработка. В профиле производства/WARModule/src/main/resources/prod /index.jsp должен быть собран в виде представлений/военного каталога. В профиле разработки/WARModule/src/main/resources/dev /index.jsp следует скопировать в каталог представлений/военных.

Для этого я пытаюсь использовать maven-resources-plugin, который я настраиваю в war pom.xml.

<properties> 
    <prodResourcesDir>${basedir}/src/main/resources/prod</prodResourcesDir> 
    <devResourcesDir>${basedir}/src/main/resources/dev</devResourcesDir> 
    <viewsDir>${basedir}/target/WARModule/views</viewsDir> 
</properties> 

<profiles> 
    <profile> 
     <id>development</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.6</version> 
        <executions> 
         <execution> 
          <id>copy_development_index.jsp</id> 
          <phase>prepare-package</phase> 
          <goals> 
           <goal>copy-resources</goal> 
          </goals> 
          <configuration> 
           <outputDirectory>${viewsDir}</outputDirectory> 
           <resources> 
            <resource> 
             <directory>${devResourcesDir}</directory> 
             <filtering>true</filtering> 
             <includes> 
              <include>index.jsp</include> 
             </includes> 
            </resource> 
           </resources> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
    <profile> 
     <id>production</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.6</version> 
        <executions> 
         <execution> 
          <id>copy_production_index.jsp</id> 
          <phase>prepare-package</phase> 
          <goals> 
           <goal>copy-resources</goal> 
          </goals> 
          <configuration> 
           <outputDirectory>${viewsDir}</outputDirectory> 
           <resources> 
            <resource> 
             <directory>${prodResourcesDir}</directory> 
             <includes> 
              <include>index.jsp</include> 
             </includes> 
            </resource> 
           </resources> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

Как вы можете видеть выше, я создаю два профиля (производство и разработка) и настройка плагина ресурсов по каждому из них.

Когда я запускаю mvn install -P any_of_the_profiles, index.jsp не копируется в указанное место назначения. Вместо этого я получаю оригинальную версию. Может ли кто-нибудь помочь мне разобраться в этом?

Ниже логе:

$ mvn -P production install 
[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Reactor Build Order: 
[INFO] 
[INFO] ParentProject 
[INFO] WebModule Maven Webapp 
[INFO] EARModule 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building ParentProject 0.0.2-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ ParentProject --- 
[INFO] Installing D:\workspace\mvn_projects\ParentProject\pom.xml to C:\Users\a048148\.m2\repository\my\org\ParentProject\0.0.2-SNAPSHOT\ParentProject-0.0.2-SNAPSHOT.pom 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building WebModule Maven Webapp 0.0.2-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebModule --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 10 resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebModule --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compilation messages... 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebModule --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory D:\workspace\mvn_projects\ParentProject\WebModule\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ WebModule --- 
[INFO] No sources to compile 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebModule --- 
[INFO] No tests to run. 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:copy-resources (copy_index.jsp) @ WebModule --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 1 resource 
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ WebModule --- 
[INFO] Packaging webapp 
[INFO] Assembling webapp [WebModule] in [D:\workspace\mvn_projects\ParentProject\WebModule\target\WebModule] 
[INFO] Processing war project 
[INFO] Copying webapp resources [D:\workspace\mvn_projects\ParentProject\WebModule\src\main\webapp] 
[INFO] Webapp assembled in [3122 msecs] 
[INFO] Building war: D:\workspace\mvn_projects\ParentProject\WebModule\target\WebModule.war 
[INFO] WEB-INF\web.xml already added, skipping 
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebModule --- 
[INFO] Installing D:\workspace\mvn_projects\ParentProject\WebModule\target\WebModule.war to C:\Users\a048148\.m2\repository\my\org\WebModule\0.0.2-SNAPSHOT\WebModule-0.0.2-SNAPSHOT.war 
[INFO] Installing D:\workspace\mvn_projects\ParentProject\WebModule\pom.xml to C:\Users\a048148\.m2\repository\my\org\WebModule\0.0.2-SNAPSHOT\WebModule-0.0.2-SNAPSHOT.pom 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building EARModule 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-ear-plugin:2.8:generate-application-xml (default-generate-application-xml) @ EARModule --- 
[INFO] Generating application.xml 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EARModule --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-ear-plugin:2.8:ear (default-ear) @ EARModule --- 
[INFO] Copying artifact [war:com.bbh:WebModule:0.0.1-SNAPSHOT] to [WebModule-0.0.1-SNAPSHOT.war] 
[INFO] Could not find manifest file: D:\workspace\mvn_projects\ParentProject\EARModule\target\ParentProject\META-INF\MANIFEST.MF - Generating one 
[INFO] Building jar: D:\workspace\mvn_projects\ParentProject\EARModule\target\ParentProject.ear 
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ EARModule --- 
[INFO] Installing D:\workspace\mvn_projects\ParentProject\EARModule\target\ParentProject.ear to C:\Users\a048148\.m2\repository\my\org\EARModule\0.0.1-SNAPSHOT\EARModule-0.0.1-SNAPSHOT.ear 
[INFO] Installing D:\workspace\mvn_projects\ParentProject\EARModule\pom.xml to C:\Users\a048148\.m2\repository\my\org\EARModule\0.0.1-SNAPSHOT\EARModule-0.0.1-SNAPSHOT.pom 
[INFO] ------------------------------------------------------------------------ 
[INFO] Reactor Summary: 
[INFO] 
[INFO] ParentProject .......................................... SUCCESS [ 0.229 s] 
[INFO] WebModule Maven Webapp ................................ SUCCESS [ 19.470 s] 
[INFO] EARModule ............................................. SUCCESS [ 3.049 s] 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 22.892 s 
[INFO] Finished at: 2016-12-12T15:18:14+01:00 
[INFO] Final Memory: 39M/247M 
[INFO] ------------------------------------------------------------------------ 

ответ

0

Я в конечном итоге выяснить, что Maven-ресурсы-плагин прекрасно работает для ресурсов, а не веб-ресурсов (JSP).

Поэтому я переключил свой подход на maven-war-plugin filtering feature и указав путь назначения. Таким образом, в разделе профили в моем веб-pom.xml закончилась так:

<profiles> 
    <profile> 
     <id>development</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>3.0.0</version> 
        <configuration> 
         <webResources> 
          <resource> 
           <directory>${devResourcesDir}</directory> 
           <filtering>true</filtering> 
           <targetPath>views</targetPath> <!-- target/WebModule/ subdirectory --> 
           <include>index.jsp</include> 
          </resource> 
         </webResources> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
    <profile> 
     <id>production</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>3.0.0</version> 
        <configuration> 
         <webResources> 
          <resource> 
           <directory>${prodResourcesDir}</directory> 
           <filtering>true</filtering> 
           <targetPath>views</targetPath> <!-- target/WebModule/ subdirectory --> 
           <include>index.jsp</include> 
          </resource> 
         </webResources> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

Это говорит Maven-боевой плагин для перемещения index.jsp из указанного каталога ресурсов в целевых/WebModule/просмотров каталог. Все это делается военным плагином непосредственно перед упаковкой войны, поэтому нет необходимости указывать фазу жизненного цикла.