2013-11-14 66 views
0

我正在開發一個必須在樹莓派上運行的JavaFx應用程序。 我遵循了所有步驟在Raspberry上安裝jdk1.8,下載maven 3.1.1並將項目複製到我的樹莓上。raspberry pi + maven + jdk1.8 + javafx

當運行

mvn clean package 

生成成功,但是當我運行命令

java -cp app.jar my.main.class 

如這裏描述的(https://wiki.openjdk.java.net/display/OpenJFX/OpenJFX+on+the+Raspberry+Pi#OpenJFXontheRaspberryPi-RunningaJDKEarlyAccessbuildontheRaspberryPi

我收到此錯誤:

Exception in Application start method 
java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:367) 
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:305) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894) 
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56) 
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158) 
    at java.lang.Thread.run(Thread.java:744) 
Caused by: java.lang.NoClassDefFoundError: javafx/scene/media/Media 
    at com.ilgala.dmp.components.Playlist.createPlayer(Playlist.java:78) 
    at com.ilgala.dmp.components.Playlist.initPlaylist(Playlist.java:55) 
    at com.ilgala.dmp.components.Playlist.<init>(Playlist.java:44) 
    at com.ilgala.dmp.videoPlayer.VideoPlayer.<init>(VideoPlayer.java:28) 
    at com.ilgala.dmp.App.start(App.java:44) 
    at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837) 
    at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:331) 
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:297) 
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:294) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:294) 
    at com.sun.glass.ui.lens.LensApplication$RunnableEvent.dispatch(LensApplication.java:182) 
    at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:861) 
    at com.sun.glass.ui.lens.LensApplication.access$1700(LensApplication.java:58) 
    at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:914) 
    ... 1 more 
Caused by: java.lang.ClassNotFoundException: javafx.scene.media.Media 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:359) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:348) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:347) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    ... 16 more 
Exception running application my.app 

任何人都可以幫我嗎?我已經包括了jfxrt我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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>my.group.Id/groupId> 
    <artifactId>my.artifact.Id</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0</version> 
    <name>App</name> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <mainClass>com.ilgala.dmp.App</mainClass> 
          <classpathPrefix>dependency-jars/</classpathPrefix> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.8</version> 
       <executions> 
        <execution> 
         <id>copy-dependencies</id> 
         <phase>package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
          <includeGroupIds>com.oracle</includeGroupIds> 
          <includeArtifactIds>javafx</includeArtifactIds> 
          <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>com.oracle</groupId> 
      <artifactId>javafx</artifactId> 
      <version>2.2</version> 
      <scope>system</scope> 
      <systemPath>/path/to/jfxrt.jar</systemPath> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 
+0

你真的不應該使用Java 8一個真正的項目呢。無論如何,你在你的pom中將你的項目指定爲Java 7。爲什麼你會使用Java 8作爲運行時環境? –

+0

嗯,我遵循了我在Oracle JavaFx頁面找到的指南,這就是爲什麼我使用那個。樹莓已經JDK1.7.0_40我應該使用那個呢? – IlGala

+0

我無法想象他們爲什麼會推薦早期訪問構建。我會使用Java 7進行有效的使用。儘管這可能與您的問題無關。 –

回答

1

您應該直接看http://zenjava.com/javafx/maven/

JavaFX的Maven插件:https://github.com/zonski/javafx-maven-plugin

這是一個偉大的插件構建javafx應用程序,您可以使用其命令將jfxrt.jar鏈接到maven版本:

mvn com.zenjava:javafx-maven-plugin:2.0:fix-classpath 

下面是命令的描述:http://zenjava.com/javafx/maven/fix-classpath.html

我也引用:

If you don't want to use the fix-classpath Maven command or have problems when running it. You can try manually moving the JAR file yourself from the lib directory to the ext directory. There is no more magic required than that.

+0

我得到這個錯誤與zenjava插件,運行它與Maven 3.0.5在樹莓上: 無法執行目標com.zenjava:javafx-maven-plugin:2.0:fix-classpath(default-cli)on project standalone- pom:目標com.zenjava的執行默認cli:javafx-maven-plugin:2.0:fix-classpath失敗:插件com.zenjava:javafx-maven-plugin:2.0或其某個依賴關係無法解析:無法找到工件javafx-packager:javafx-packager:jar:1.7在指定路徑/​​usr/lib/jvm/jdk-7-oracle-armhf/jre/../lib/ant-javafx.jar – IlGala

+0

@IIGala這是一個bug,get 2.0-SNAPSHOT解決它:https://github.com/zonski/javafx-maven-plugin/issues/27 – zenbeni

+0

完成後,jvm文件夾上的lib文件夾丟失,然後該插件工作。現在樹莓似乎做我需要的,謝謝大家! – IlGala