如何在Maven中正确包含Java源代码?

Lau*_*t T 16 gwt maven

我正在研究一个非常简单的Java博客引擎,以便学习多种技术.

Tech:Spring IoC,Hibernate,jUnit,GWT和Maven.

我创建了两个Maven项目:一个核心项目和一个GWT项目(其核心项目有一个参考)

可以通过https://github.com/LaurentT/BlogEngineCore访问代码

我的目标如下:我想要包含Java源代码和XML,因为我的GWT项目需要Java源代码才能将其编译成JavaScript.

我试图在<build>元素中使用以下代码:

     <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.java</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*xml</include>
                <include>**/*.*properties</include>
            </includes>
        </resource>
    </resources>
Run Code Online (Sandbox Code Playgroud)

我的jUnit测试用于在添加之前传递和完成,但现在他们甚至没有完成他们正在挂...

我不知道发生了什么,所以我想知道是否还有其他方法可以包含Java源代码,或者我是否只是做错了.

任何线索?

Sea*_*oyd 23

更干净的maven方式是附加一个单独的源罐.

有一些标准方法可以使用maven源插件在您的构建中生成它:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.2.1</version>
  <executions>
    <execution>
      <id>attach-sources</id>
      <phase>verify</phase>
      <goals>
        <goal>jar-no-fork</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

除了核心项目jar之外,您的GWT项目现在可以引用您的核心项目源:

<dependency>
  <groupId>your.project</groupId>
  <artifactId>core</artifactId>
  <version>the.same.version</version>
  <classifier>sources</classifier>
  <scope>provided</scope><!-- use for compilation only -->
</dependency>
Run Code Online (Sandbox Code Playgroud)


Mik*_*one 11

尝试在目录路径前面加上$ {basedir}.

<resource>
    <directory>${basedir}/src/main/java</directory>
</resource>
Run Code Online (Sandbox Code Playgroud)