Create runnable jar with maven 3.1 using maven-dependency-plugin doesn't create runnable jar

后端 未结 7 1371
予麋鹿
予麋鹿 2021-01-15 16:43

Using Maven 3.1
Eclipse Helios

Aspekt:

Try to create a runable jar file using maven-jar/dependency-plugins.

Problem:

相关标签:
7条回答
  • 2021-01-15 16:48

    Are you sure your java version, launched at command line, is equal or greater than that used by maven when compiling? try java -version

    0 讨论(0)
  • 2021-01-15 16:50

    via command line, go to the parent dir of "dependency-jars" and run: java -jar program.jar

    0 讨论(0)
  • 2021-01-15 16:54

    The simplest solution is to use maven-assembly-plugin like this:

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <!-- NOTE: We don't need a groupId specification because the group is
                 org.apache.maven.plugins ...which is assumed by default.
             -->
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
            </configuration>
            [...]
    </project>
    
    0 讨论(0)
  • 2021-01-15 16:54

    Ok, i solved the second/updated Problem:

    I first startet to use eclipse with maven plugin to create the runable jar file. This runs in the described problems.

    After all i tried to use maven 3.1 from console application and after all it works. Seems that eclipse maven plugin has some problems.

    0 讨论(0)
  • 2021-01-15 17:01

    Not sure what's going on, but this is what my pom looks like for building a runnable jar using shade:

     <build>
            <resources>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                    <filtering>false</filtering>
                    <includes>
                        <include>schema.xsd</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>stand-alone</shadedClassifierName>
                        <artifactSet>
                            <excludes>
                                <exclude>org.slf4j:slf4j-api:jar:</exclude>
                                <exclude>org.slf4j:slf4j-log4j12:jar:</exclude>
                                <exclude>org.slf4j:jcl-over-slf4j:jar:</exclude>
                                <exclude>commons-logging:commons-logging:jar:</exclude>
                                <exclude>commons-logging:commons-logging-api:jar:</exclude>
                            </excludes>
                        </artifactSet>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <finalName>MyFinalRunnableJarName</finalName>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>class.with.main.Method</mainClass>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    0 讨论(0)
  • 2021-01-15 17:01

    Use this command to create jar file of any maven project.

    mvn clean compile install

    0 讨论(0)
提交回复
热议问题