问题
I'm working on a very simple blog engine in Java in order to learn multiple technologies.
Tech: Spring IoC, Hibernate, jUnit, GWT, and Maven.
I created two Maven projects: a core project and a GWT project (which has a reference on the core one)
Code is accessible at https://github.com/LaurentT/BlogEngineCore
My goal is the following: I want to include Java sources and XML since my GWT project is going to need the Java sources to compile it into JavaScript.
I tried to use the following code in the <build> element:
     <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>
My jUnit tests used to pass and finish before that add but now they are not even finishing they are hanging...
I have no clue what's going on, so I want to know if there are other ways to include Java sources or if I'm just doing it wrong.
Any clue?
回答1:
try including the ${basedir} in front of the directory path.
<resource>
    <directory>${basedir}/src/main/java</directory>
</resource>
    回答2:
The cleaner maven way would be to attach a separate source jar.
There are standard ways to generate it in your build using the maven source plugin:
<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>
And your GWT project can now reference your core project sources in addition to your core project jar:
<dependency>
  <groupId>your.project</groupId>
  <artifactId>core</artifactId>
  <version>the.same.version</version>
  <classifier>sources</classifier>
  <scope>provided</scope><!-- use for compilation only -->
</dependency>
    回答3:
You can find how to setup maven for multimodule project here.
Where's the *gwt.xml file?
If the  tag shown is part of the core project's pom.xml file, then you should also add  <include>**/*.gwt.xml</include>: 
<resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.java</include>
            <include>**/*.gwt.xml</include>
        </includes>
</resource>
    回答4:
In contrast to the other answers, my approach copies all *.gwt.xml module descriptors and only the java source files that are actually specified in the module descriptors. You also don't need to repeat yourself in POM and module descriptors.
Update your pom with:
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.7.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
and your *.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module>
    <!-- Specify the paths for translatable code -->
    <source path='shared' />
</module>
org:codehaus.mojo:gwt-maven-plugin docs
gwt:resources
Description: Copy GWT java source code and module descriptor as resources in the build outputDirectory. Alternative to declaring a<resource>in the POM with finer filtering as the module descriptor is read to detect sources to be copied.
Implementation: org.codehaus.mojo.gwt.GwtResourcesMojo
Language: java
Bound to phase: process-resources
来源:https://stackoverflow.com/questions/8730168/how-to-properly-include-java-sources-in-maven