将多个jar组合成一个(使用maven)

Hin*_*ara 3 java intellij-idea maven-3 javafx-2 javafx-8

我在javafx中有一个项目,我有3个依赖项我尝试使用maven将它们与我的primaryale jar结合起来:结果我得到了一个罐子(1.82mb)但是当我点击它时他没有启动注意出现.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
    <dependencies>
        <dependency>
            <groupId>org.scilab.forge</groupId>
            <artifactId>jlatexmath</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>fxgraphics2d</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>8.0.6_20</version>
        </dependency>
    </dependencies>
    <groupId>groupId</groupId>
    <artifactId>FXCalc</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>
Run Code Online (Sandbox Code Playgroud)

这是一些截图:

在此输入图像描述 在此输入图像描述

问题:我得到的jar文件不起作用,它不想启动,我尝试使用蚂蚁和gradle但我不知道如何使用它们.

编辑:尝试解决方案后,我得到一个罐子,但它仍然没有启动,我没有错误. 在此输入图像描述 编辑2:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
    <dependencies>
        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>fxgraphics2d</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.scilab.forge</groupId>
            <artifactId>jlatexmath</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>8.0.6</version>
        </dependency>
    </dependencies>
    <build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>sample.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </build>
    <groupId>groupId</groupId>
    <artifactId>CalculatorFX</artifactId>
    <version>1.0-SNAPSHOT</version>


</project>
Run Code Online (Sandbox Code Playgroud)

Adi*_*Adi 7

将以下插件添加到您的后续pom.xml依赖项:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>sampler.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

然后mvn package从您的项目所在的基目录运行该命令.这将在目标文件夹中生成一个jar.