2014-08-31 22 views
2

我在javafx中有一个项目,我有3个依赖关系我尝试将它们与我的principale jar结合使用maven: 结果我得到了一个jar(1.82mb),但当我点击他不会启动注意出现。将多个jar组合成一个(使用maven)

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> 

,这是一些截图:

enter image description here enter image description here

的问题:我这么想的工作jar文件,它这么想的要推出,我尝试过使用ant和gradle,但我不知道如何使用它们。

编辑:试过解决方案后,我得到一个罐子,但它仍然没有启动,我没有错误。 enter image description here 编辑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> 
+0

你怎么结合他们? – Adi 2014-08-31 12:31:42

+0

我使用了“添加框架支持”,然后通过添加依赖项(在我的情况下为3)来修改pom.xml文件,然后构建一个工件,我得到了一个不想启动的jar。 – HinoHara 2014-08-31 12:35:38

+0

你需要使用[Maven assembly plugin](http://maven.apache.org/plugins/maven-assembly-plugin/)在maven中创建具有依赖关系的单个jar。 – Adi 2014-08-31 12:37:17

回答

4

添加以下插件您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> 

然后从你的基本目录,你的项目是运行mvn package命令。这将在目标文件夹中生成一个jar文件。

+0

是的,我得到一个jar文件,但它不工作,我不知道为什么。 (看看我在问题中添加的图片) – HinoHara 2014-09-01 13:47:37

+0

@HinoHara - 请参阅关于如何配置主类的编辑答案。让我知道它是否有效。 – Adi 2014-09-01 14:52:46

+0

嗨,谢谢你的回答,但我仍然有同样的问题,我会复制pom.xml给你检查它。谢谢@Adi – HinoHara 2014-09-01 16:05:54