简体   繁体   English

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

[英]Combine multiple jar into one (using maven)

I have a project in javafx , I have 3 dependencies I try to combine them with my principale jar using maven : The result I got a jar (1.82mb) but when I click he dosen't launch noting appears. 我在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>

and this is some screenshot : 这是一些截图:

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

The problem : the jar file I got dosen't work , it dosen't want to launch , I tried using ant and gradle but I don't know how to use them. 问题:我得到的jar文件不起作用,它不想启动,我尝试使用蚂蚁和gradle但我不知道如何使用它们。

EDIT : After trying the solution I get a jar but it still dosen't launch and I have no error. 编辑:尝试解决方案后,我得到一个罐子,但它仍然没有启动,我没有错误。 在此输入图像描述 EDIT 2 : 编辑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>

Add the following plugin to your pom.xml after dependencies: 在依赖项之后将以下插件添加到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>

Then run the mvn package command from your base directory, where your project is. 然后从您的项目所在的基目录运行mvn package命令。 This will generate a single jar in the target folder. 这将在目标文件夹中生成一个jar。

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

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