1

I need to include src/test/java files to my jar with dependancies. But when I create the jar it fails because it cannot find the classes. Here is the pom section. Any help would be appreciated. And i compile with: mvn clean assembly:single

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
   </configuration>
   <executions>
     <execution>
       <phase>package</phase>
       <goals>
         <goal>single</goal>
       </goals>
     </execution>
   </executions>
</plugin>
Richard
  • 239
  • 1
  • 3
  • 14
  • 2
    Could you explain why you want to do that? The whole purpose of that test sources directory is that those files are _not_ included in the build. – tobias_k Apr 01 '14 at 20:27
  • Yes I can, I made a guy for testing and I want to be able to run it from the jar. But because its testing it is in src/test/java – Richard Apr 01 '14 at 20:31
  • Alternatively, you might put the test GUI into a second module... – tobias_k Apr 01 '14 at 20:35

3 Answers3

1

Or you can use maven resource plugin and mark the src/test/java as additional source

similar question is asked here

Community
  • 1
  • 1
WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
0

by default it is not included, you can have greater amount of flexibility with maven assembly plugin you can use that to generate jar with whatever content you want to put in

jmj
  • 237,923
  • 42
  • 401
  • 438
  • i am using maven assembly plugin, could you provide an example of how I would add src/test/java using maven assembly plugin? – Richard Apr 01 '14 at 20:35
  • check this specially `` http://maven.apache.org/guides/mini/guide-assemblies.html – jmj Apr 01 '14 at 20:36
0

Wanted to share how I got it to work, although very ugly. To reiterate I wanted to add the test-classes to the class path only when I made my jar with dependancies. What I did:

switched from assembly-pludin to shade-plugin And moved the .class files i needed from target/test-classes to proper place in the jar

<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
    <file>target/test-classes/path/to/class/i/need/file.class</file>
    <resource>in/classpath/destination/of/class/i/need/file.class</resource>
</transformer>

its glorified copy paste and did not see a way to do so via directory so did it 1 .class at a time.

Very ugly, not dynamic, and I am still looking for a better way. But for now it will do.

Richard
  • 239
  • 1
  • 3
  • 14