Maven - 如何在使用 maven-source-plugin

问题描述

我正在尝试将我的应用程序的源代码打包到一个 .JAR 文件中,我使用了 maven-source-plugin。我将以下部分添加到 pom.xml 中 -

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.1.0</version>
                <extensions>false</extensions>
                <inherited>true</inherited>
                <configuration>
                   <outputDirectory>c:\app\workspace</outputDirectory>
                    <finalName>app.jar</finalName>
                    <attach>false</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
           </plugin>

在outputDirectory位置可以看到生成的jar中的源文件,但是缺少JSP文件,只能看到.java文件。我怎样才能打包 .jsp 文件?我的应用程序将这些 jsp 文件存储在 src/main/webapps 文件夹下。我在生成的 jar 中没有看到 webapps 文件夹。请指教。

解决方法

在我的项目中,我使用的是 maven-assembly-plugin:

pom.xml

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
                <id>package-project-ui</id>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>mvn-assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

在模块的同一个主目录下一个名为mvn-assembly的文件夹中,添加一个文件assembly.xml

assembly.xml 的内容

<assembly>
  <id>${project.name}</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>YourDirectoryWhichHasYourJSPs</directory>
      <outputDirectory></outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

有用的 StackOverflow:Including dependencies in a jar with Maven

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...