Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven assembly - jar misses own classes

I want to create a jar file from a maven project. I need to use an own assembly.xml because I need to exclude a few .so files:

assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

  <id>assembly-with-so</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <!-- package the regular dependencies -->
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>true</unpack>
      <scope>runtime</scope>
      <excludes>
        <exclude>jcuda:libJCublas:so:linux-x86_64:0.6.5</exclude>
        [...]
      </excludes>
    </dependencySet>
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>jcuda:libJCublas:so:linux-x86_64:0.6.5</include>
        [...]
      </includes>
    </dependencySet>
  </dependencySets>
</assembly>

pom.xml

[...]
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptor>src/main/assembly/assembly.xml</descriptor>
                <appendAssemblyId>false</appendAssemblyId>
                <archive>
                    <manifest>
                        <mainClass>org.test.Test</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        [...]
</build>

When I start the jar file using java -jar File.jar I'm getting the error that the class org.test.Test is missing. When I open the .jar file to have a look what's in it, I see that every file of the dependencies are there but the files of the main project are missing.

like image 629
user1406177 Avatar asked Oct 23 '14 15:10

user1406177


1 Answers

Well for someone with the same problem. It happened to me also. And the answer is:

Did you check that your class is not inside the /src/test/java folder? Maven only copies classes to the jar whose are inside the folder /src/main/java.

I know it is weird but it happens when you want to pack a Selenium automated test.

the solution of course is to move your class to /src/main/java

Hope it helps

like image 150
Carlos Rafael Ramirez Avatar answered Nov 19 '22 10:11

Carlos Rafael Ramirez