3

I use maven-source-plugin to generated java-source. However doing "mvn clean ; mvn package" does not generate a project-sources.jar in the target directory.

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

info:

[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ weibo4j ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ weibo4j ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ weibo4j ---
[INFO] Building jar: F:\step-by-step\weibo4j\target\weibo4j-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-source-plugin:2.3:jar-no-fork (attach-sources) @ weibo4j ---
[INFO] No sources in project. Archive not created.
HJLebbink
  • 566
  • 1
  • 7
  • 23
v11
  • 1,684
  • 4
  • 24
  • 47
  • Do you have source? The above maven log is from `testCompile` - what happens before that? – Raghuram Oct 10 '14 at 07:30
  • 1
    Ensure you have the sources in the right folder following Maven folders convention – agamesh Oct 10 '14 at 07:58
  • @Raghuram If I want to generated java-source, Do I need copy code to resources file ? – v11 Oct 10 '14 at 08:07
  • @Raghuram I want to use maven to finish work like using eclpse -> export -> export java source files and resource. How can I do it? Thank you. – v11 Oct 10 '14 at 08:10
  • Maybe, if include oprion "forceCreation", jar will be created: http://maven.apache.org/plugins/maven-source-plugin/jar-no-fork-mojo.html – pasha701 Oct 10 '14 at 10:14
  • Can you add the full output of your build run in particular where maven-compiler-pugin tries to compile the productions code `src/main/java`? If maven-sources-plugin says it `No sources in project.` that means you don't have something in `src/main/java`...? – khmarbaise Oct 10 '14 at 21:12

1 Answers1

1

If you have your sources in a directory that maven does not consider a source directory -- such as webapp -- your files will not be put in your project-sources.jar.

Solution: signal to maven what your source directory is. Add:

<build>
    <sourceDirectory>${basedir}/src/main/webapp</sourceDirectory>
</build>
HJLebbink
  • 566
  • 1
  • 7
  • 23