简体   繁体   English

将Jsprit Maven项目导出到可执行jar

[英]Export a jsprit maven project to an executable jar

I'm trying to create an executable .jar from a maven project using eclipse mars. 我正在尝试使用Eclipse Mars从Maven项目创建可执行文件.jar。 The project itself can be found on https://github.com/jsprit/jsprit 该项目本身可以在https://github.com/jsprit/jsprit上找到

So far I have successfully imported jsprit to eclipse as a maven project and I am able to run examples as Java Application. 到目前为止,我已经成功将jsprit作为maven项目导入到eclipse中,并且能够将示例作为Java应用程序运行。

I haven't yet been very successful at exporting it as an executable jar. 我还没有很成功地将其导出为可执行jar。 Let's say I want to export SimpleExample.java. 假设我要导出SimpleExample.java。 I have created the .jar but if I try to run jsprit-examples-1.6.2-SNAPSHOT-jar-with-dependencies.jar I get the following error message: 我创建了.jar,但是如果尝试运行jsprit-examples-1.6.2-SNAPSHOT-jar-with-dependencies.jar,则会收到以下错误消息:

Error: Could not find or load main class jsprit.examples.SimpleExample 错误:找不到或加载主类jsprit.examples.SimpleExample

The pom.xml which is located under jsprit-examples is following: 位于jsprit-examples下的pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
    <groupId>jsprit</groupId>
    <artifactId>jsprit</artifactId>
    <version>1.6.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>jsprit-examples</artifactId>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-enforcer-plugin</artifactId>
                                    <versionRange>[1.0.0,)</versionRange>
                                    <goals>
                                        <goal>enforce</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore/>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>                
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>jsprit.examples.SimpleExample</mainClass>
                        </manifest>
                    </archive>
                    <descriptors>
                        <descriptor>src/main/resources/assemblies/jar-with-dependencies.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                 </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<repositories>
    <repository>
        <id>jsprit-snapshots</id>
        <url>https://github.com/jsprit/mvn-rep/raw/master/snapshots</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>jsprit-instances</artifactId>
        <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>jsprit-core</artifactId>
        <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>jsprit-analysis</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

Everything else is as same as in the github repository. 其他所有内容都与github存储库中的相同。 I ran 'Maven Build...' on jsprit-examples. 我在jsprit-examples上运行了“ Maven Build ...”。 Under 'Edit Configuration->Goals' I did 'clean package assembly:single'. 在“编辑配置->目标”下,我执行了“清理程序包Assembly:single”。

This is my first experience with a maven build so it might be a very simple problem to someone who has some experience with maven. 这是我第一次使用Maven构建,因此对于具有Maven经验的人来说,这可能是一个非常简单的问题。

Thanks! 谢谢!

I you want to put all the dependencies in one executable jar, you need to create an uber-jar. 我想将所有依赖项放在一个可执行jar中,您需要创建一个uber-jar。 I usually do this with the maven shade plugin . 我通常使用Maven Shade插件执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM