我想分发使用Maven 生成的Web应用程序的战争,其中包含源代码。如何用Maven做到这一点?
答案 0 :(得分:14)
可以将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布局。
答案 1 :(得分:3)
如果您希望源文件与您将使用的类文件位于同一目录中:
<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>
答案 2 :(得分:0)
通常我认为你会这样:(这不包括源文件,但是将它们作为单独的文件提供)
<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>
答案 3 :(得分:0)
在你的战争项目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>