2015-04-03 50 views
0

我的應用程序(JavaFX - Java 8)使用REST服務並需要Jersey庫(2.17)。 Depedencies由Maven的管理,這是我的pom.xml:JavaFX/Maven應用程序運行但它不顯示

<dependencies> 
     <dependency> 
      <groupId>org.glassfish.hk2.external</groupId> 
      <artifactId>aopalliance-repackaged</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.ow2.asm</groupId> 
      <artifactId>asm-debug-all</artifactId> 
      <version>5.0.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>hk2-api</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>hk2-locator</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>hk2-utils</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.javassist</groupId> 
      <artifactId>javassist</artifactId> 
      <version>3.18.1-GA</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.annotation</groupId> 
      <artifactId>javax.annotation-api</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2.external</groupId> 
      <artifactId>javax.inject</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>javax.servlet-api</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.ws.rs</groupId> 
      <artifactId>javax.ws.rs-api</artifactId> 
      <version>2.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.xml.bind</groupId> 
      <artifactId>jaxb-api</artifactId> 
      <version>2.2.7</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-common</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet-core</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.bundles.repackaged</groupId> 
      <artifactId>jersey-guava</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-jaxb</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-server</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.osgi</groupId> 
      <artifactId>org.osgi.core</artifactId> 
      <version>4.2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>osgi-resource-locator</artifactId> 
      <version>1.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.persistence</groupId> 
      <artifactId>persistence-api</artifactId> 
      <version>1.0</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.validation</groupId> 
      <artifactId>validation-api</artifactId> 
      <version>1.1.0.Final</version> 
     </dependency> 
    </dependencies> 

    <properties> 
     <maven_compiler_source>1.8</maven_compiler_source> 
     <maven_compiler_target>1.8</maven_compiler_target> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

當我運行該應用程序,它運行沒有錯誤或警告(我可以看到在Eclipse控制檯清晰的輸出),我從CMD的運行看到錯誤,但沒有人。該應用程序運行(可以看到該進程),但不顯示。

也許JavaFX和Maven的不兼容?我應該創建一個JavaFX項目,而不是Maven項目?如果我有,我怎麼可以添加一個文件夾lib而不是所有的JAR直接?

我很感激任何幫助。

+0

檢查該JVM的日誌文件。應該告訴你一些事情。 – StackFlowed 2015-04-03 15:27:51

+0

感謝您的回答。它看起來像Maven與JavaFX不兼容。 – 2015-04-03 16:11:36

回答

0

溶液只添加幾行:

只需添加主類:

<main.class>me.localtest.views.Main</main.class> 

並添加的Maven插件包:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.4</version> 
    <configuration> 
     <archive> 
      <manifest> 
       <addClasspath>true</addClasspath> 
       <mainClass>${main.class}</mainClass> 
      </manifest> 
     </archive> 
    </configuration> 
</plugin> 

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"> 

    <modelVersion>4.0.0</modelVersion> 
    <groupId>me.localtest</groupId> 
    <artifactId>CustomersAppClient</artifactId> 
    <version>0.0.1</version> 
    <name>CustomersAppClient</name> 

    <dependencies> 
     <dependency> 
      <groupId>org.glassfish.hk2.external</groupId> 
      <artifactId>aopalliance-repackaged</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.ow2.asm</groupId> 
      <artifactId>asm-debug-all</artifactId> 
      <version>5.0.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>hk2-api</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>hk2-locator</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>hk2-utils</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>org.javassist</groupId> 
      <artifactId>javassist</artifactId> 
      <version>3.18.1-GA</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.annotation</groupId> 
      <artifactId>javax.annotation-api</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2.external</groupId> 
      <artifactId>javax.inject</artifactId> 
      <version>2.4.0-b10</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>javax.servlet-api</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.ws.rs</groupId> 
      <artifactId>javax.ws.rs-api</artifactId> 
      <version>2.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.xml.bind</groupId> 
      <artifactId>jaxb-api</artifactId> 
      <version>2.2.7</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-common</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet-core</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.bundles.repackaged</groupId> 
      <artifactId>jersey-guava</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-jaxb</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-server</artifactId> 
      <version>2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.osgi</groupId> 
      <artifactId>org.osgi.core</artifactId> 
      <version>4.2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.hk2</groupId> 
      <artifactId>osgi-resource-locator</artifactId> 
      <version>1.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.persistence</groupId> 
      <artifactId>persistence-api</artifactId> 
      <version>1.0</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.validation</groupId> 
      <artifactId>validation-api</artifactId> 
      <version>1.1.0.Final</version> 
     </dependency> 
    </dependencies> 

    <properties> 
     <maven_compiler_source>1.8</maven_compiler_source> 
     <maven_compiler_target>1.8</maven_compiler_target> 
     <!-- name of the jar --> 
     <jar.final.name>CustomersApp</jar.final.name> 
     <!-- class name --> 
     <main.class>me.localtest.views.Main</main.class> 
    </properties> 

    <build> 
     <finalName>${jar.final.name}</finalName> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <!-- Mavven package plugin --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <mainClass>${main.class}</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

無需禪JavaFX插件了。希望對某人有幫助。

1

最可能的問題是罐子的包裝。您需要打包runnable jar而不是普通的罐子。

你有很多選擇建立一個使用JavaFX Maven Plugin

<plugin> 
    <groupId>com.zenjava</groupId> 
    <artifactId>javafx-maven-plugin</artifactId> 
    <version>8.1.1</version> 
    <configuration> 
     <mainClass>fully.qualified.MainClass</mainClass> 
    </configuration> 
</plugin> 

你會發現你需要在documentation

你也可以使用一個maven-assembly-plugin知道的一切最好的有:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <descriptorRefs> 
     <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     <archive> 
     <manifest> 
      <mainClass>fully.qualified.MainClass</mainClass> 
     </manifest> 
     </archive> 
    </configuration> 
</plugin> 

這將在您的目標文件夾內創建一個包含ProjectName-Version-SNAPSHOT-jar-with-dependencies.jar的罐子。

你可以在它上面運行上雙擊罐子或在終端使用以下命令:

java -jar jarName 
相關問題