编译类与maven目标“编译”不同,并在目标文件夹中自动生成

时间:2012-09-04 05:17:59

标签: maven maven-compiler-plugin

在Spring3 + Maven + Tomcat6 Web项目中..

我尝试在REST api控制器中使用相同的RequestMapping 因为..我需要不同用途的不同战争。

所以,我生成了相同名称的Controller,但不同的包 例如......
1. xxx.controller.agent.UserController
2. xxx.controller.console.UserController

在pom.xml中..
1. maven - >建立(战争:战争) - > get console.war包含xxx.controller.agent.UserController
2.取消注释testExcludes中的注释行并排除
3.评论testExcludes中的未注释行并排除
4. maven - >更新项目配置
5. maven - >建立(战争:战争) - > get agent war包括xxx.controller.console.UserController

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <testExcludes>
            <exclude>com/test/store/controller/agent/*.java</exclude>
            <exclude>com/test/rbac/controller/agent/*.java</exclude>
            <!-- <exclude>com/test/store/controller/console/*.java</exclude>
            <exclude>com/test/rbac/controller/console/*.java</exclude> -->
        </testExcludes>
        <excludes>
            <exclude>com/test/store/controller/agent/*Controller.java</exclude>
            <exclude>com/test/rbac/controller/agent/*Controller.java</exclude>                      
            <!-- <exclude>com/test/store/controller/console/*Controller.java</exclude>
            <exclude>com/test/rbac/controller/console/*Controller.java</exclude> -->
        </excludes>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

但是,我不想为每个war构建编辑pom.xml。 我尝试使用maven profiles元素构建每个war文件。 所以,我编辑了我的pom.xml,如下所示..

<properties>
<exclude.console.store>com/test/store/controller/agent/**</exclude.console.store>
<exclude.console.rbac>com/test/rbac/controller/agent/**</exclude.console.rbac>
<exclude.agent.store>com/test/store/controller/console/**</exclude.agent.store>
<exclude.agent.rbac>com/test/rbac/controller/console/**</exclude.agent.rbac>
</properties>
...
<profiles>
    <profile>
        <id>console</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <packagingExcludes>
                            WEB-INF/classes/${exclude.console.store},
                            WEB-INF/classes/${exclude.console.rbac}
                        </packagingExcludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <testExcludes>
                            <exclude>${exclude.console.store}</exclude>
                            <exclude>${exclude.console.rbac}</exclude>                      
                        </testExcludes>
                        <excludes>
                            <exclude>${exclude.console.store}</exclude>
                            <exclude>${exclude.console.rbac}</exclude>                      
                        </excludes>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>    
    </profile>

    <profile>
        <id>agent</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <packagingExcludes>
                            WEB-INF/classes/${exclude.agent.store},
                            WEB-INF/classes/${exclude.agent.rbac},
                            WEB-INF/classes/spring/task.xml
                        </packagingExcludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <testExcludes>
                            <exclude>${exclude.agent.store}</exclude>
                            <exclude>${exclude.agent.rbac}</exclude>                        
                        </testExcludes>
                        <excludes>
                            <exclude>${exclude.agent.store}</exclude>
                            <exclude>${exclude.agent.rbac}</exclude>                        
                        </excludes>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
        </build>    
    </profile>
</profiles>

Maven build ..(goal =“package”或“compile war:war”,profile =“console”或“agent”) 构建成功..(没有编译错误)但战争异常 我将war文件复制到tomcat webapp目录,并执行startup.bat文件 在控制台日志中..发生了很多错误。
也许我认为maven编译有一些问题..
我解压缩war文件的每个构建方法(使用profile和old方法) 但是,班级档案的数量不同......

感谢您的帮助,非常感谢!

0 个答案:

没有答案