【发布时间】:2010-09-04 15:13:34
【问题描述】:
我想分发使用 Maven在其中包含源代码生成的 Web 应用程序的战争。如何用 Maven 做到这一点?
【问题讨论】:
我想分发使用 Maven在其中包含源代码生成的 Web 应用程序的战争。如何用 Maven 做到这一点?
【问题讨论】:
可以将 maven-war-plugin 配置为包含源目录,因为它是 Web 资源:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${build.sourceDirectory}</directory>
<targetPath>sources</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
java 源代码将包含在战争中的sources 目录中。当然,你应该根据自己的 maven 布局调整资源目录。
【讨论】:
如果您希望源文件与您将使用的类文件位于同一目录中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${build.sourceDirectory}</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
【讨论】:
通常我认为你会这样:(这不会包括源文件,而是将它们作为单独的文件提供)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
【讨论】:
在你的战争项目的pom.xml:
<build>
...
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<attachClasses>true</attachClasses>
<classesClassifier>classes</classesClassifier>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
</build>
在你想要的项目中使用它:
<dependency>
<groupId>my-war-group</groupId>
<artifactId>my-war-artifact-id</artifactId>
<version>my-war-version</version>
<classifier>classes</classifier> <!-- THIS IS THE IMPORTANT LINE! -->
</dependency>
【讨论】: