1

使用maven-shade-plugin我正在尝试创建一个项目文件结构,如下所示:

在此处输入图像描述

问题是下面的 pom 配置没有创建 WEB-INF 目录。

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <createDependencyReducedPom>true</createDependencyReducedPom>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.my.package.Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

基本上我需要将我的 web.xml 文件、类和 lib 文件复制到项目根目录中名为 WEB-INF 的目录中。

更新:对不起,我从我的 pom 复制了错误的插件到原始问题中!

更新:如果我从 pom 声明中添加包装:<packaging>war</packaging>WEB-INF 文件结构按照 OQ 完成。但是,有了这个声明,com目录现在不包含我的包,所以找不到主类。

它看起来如何<packaging>war</packaging>

在此处输入图像描述

它应该看起来如何:

在此处输入图像描述

4

2 回答 2

0

maven-assembly插件提供了更大的灵活性,可以通过使用程序集插件轻松完成


于 2014-06-26T22:42:24.937 回答
0

有很多可能的答案可以用 maven 达到预期的效果。但是,根据我提供的更新,我发现添加maven-antrun-plugin解决了我的问题:

<plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>move-main-class</id>
                    <phase>compile</phase>
                    <configuration>
                        <tasks>
                            <copy todir="${project.build.directory}/${project.artifactId}">
                                <fileset dir="${project.build.directory}/classes/">
                                </fileset>
                            </copy>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
于 2014-06-27T07:49:40.123 回答