【发布时间】:2014-08-31 12:30:24
【问题描述】:
我在 javafx 中有一个项目,我有 3 个依赖项,我尝试使用 maven 将它们与我的 principale jar 结合起来: 结果我得到了一个 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>
这是一些截图:
问题:我得到的 jar 文件不起作用,它不想启动,我尝试使用 ant 和 gradle 但我不知道如何使用它们。
编辑: 尝试解决方案后,我得到了一个 jar,但它仍然无法启动,并且我没有错误。 编辑 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>
【问题讨论】:
-
你是如何组合它们的?
-
我使用了“添加框架支持”,然后我通过添加依赖项(在我的情况下为 3 个)修改了 pom.xml 文件,然后我构建了一个工件,我得到了一个不想启动的 jar。
-
你需要使用Maven assembly plugin在maven中创建具有依赖关系的单个jar。
-
@Adi 我下载了maven,但是我没有尝试编译什么的,因为我不知道用什么,是不是必须下载这个插件?
标签: java intellij-idea javafx-2 maven-3 javafx-8