问题描述
我测试了使用Netbeans 7.4创建JavaFX 8项目.但不幸的是没有运气.这是POM文件:
I tested to create JavaFX 8 project with Netbeans 7.4. But unfortunately with no luck. This is the POM file:
<?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>
<groupId>com.dx57dc</groupId>
<artifactId>JFX8M</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JFX8M</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.dx57dc.jfx8m.MainApp</mainClass>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
当我编译jar文件并使用Netbeans 7.3.1运行它时,出现此错误:
When I compile the jar file run it with Netbeans 7.3.1 I get this error:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (unpack-dependencies) on project JFX8M: Command execution failed. Cannot run program "C:\Program Files\Java\jdk1.8.0\jre\..\bin\javafxpackager" (in directory "D:\Documents and Settings\pterzie\My Documents\NetBeansProjects\JFX8M"): CreateProcess error=14001, This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem -> [Help 1]
当我编译项目并在Netbeans 7.4上运行它时,出现此错误堆栈:
When I compile the project and run it on Netbeans 7.4 I get this error stack:
Executing command line: C:\Program Files\Java\jdk1.8.0\jre\..\bin\javafxpackager -createjar -nocss2bin -appclass com.dx57dc.jfx8m.MainApp -srcdir D:\Documents and Settings\pterzie\My Documents\NetBeansProjects\JFX8M\target/classes -outdir D:\Documents and Settings\pterzie\My Documents\NetBeansProjects\JFX8M\target -outfile JFX8M-1.0.jar
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.782s
Finished at: Sat Aug 03 13:25:30 PDT 2013
Final Memory: 14M/34M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (unpack-dependencies) on project JFX8M: Command execution failed. Cannot run program "C:\Program Files\Java\jdk1.8.0\jre\..\bin\javafxpackager" (in directory "D:\Documents and Settings\pterzie\My Documents\NetBeansProjects\JFX8M"): CreateProcess error=14001, This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (unpack-dependencies) on project JFX8M: Command execution failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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:491)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Command execution failed.
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:367)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.8.0\jre\..\bin\javafxpackager" (in directory "D:\Documents and Settings\pterzie\My Documents\NetBeansProjects\JFX8M"): CreateProcess error=14001, This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1043)
at java.lang.Runtime.exec(Runtime.java:620)
at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:254)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:319)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:610)
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:352)
... 21 more
Caused by: java.io.IOException: CreateProcess error=14001, This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1024)
... 28 more
是否有Java 8和Maven的示例已实现并正常工作?
Is there any example with Java 8 and Maven which is implemented and working properly?
PS 删除插件后,我设法使其正常运行.我是这样编辑POM的:
P.SI managed to make it working after I remove a plugin. I edited the POM this way:
<?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>
<groupId>com.dx57dc</groupId>
<artifactId>JFX8M</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JFX8M</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass></mainClass>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<mainClass>com.dx57dc.jfx8m.MainApp</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
它仅适用于JVM8.我在POM文件中缺少重要的东西吗?
It works only for JVM 8. Am I missing something important into the POM file?
推荐答案
JavaFx 8可以正常工作,并且只能与Java 8一起工作.
还要检查当前的javaFx路线图: http://www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html
Also check the current javaFx roadmap: http://www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html
我运行它没有任何问题.
I did not have any problems getting it running.
- 下载并安装JDK8: https://jdk8.java.net/download.html 1.1.如果您不知道自己在做什么,请确保它是系统上唯一的默认jdk.
- 下载Netbeans 7.4: https://netbeans.org/downloads
- 在Netbeans中:(文件->新项目->来自原型的项目->在javafx下键入"->选择":javafx-basic-archetype)3.1.不要忘记设置组织名称
- 下载并从某处复制粘贴JavaFx 8类示例&/演示,例如:4.1.现在将项目源设置为1.8和utf-8
- 清理并构建并运行它!
- 享受!
- Download and install JDK8: https://jdk8.java.net/download.html1.1. be sure it's the oonly one and default jdk on your system if you don't know what you are doing ...
- Download Netbeans 7.4: https://netbeans.org/downloads
- In Netbeans: (File -> New project -> Project from Archetype -> "type in under javafx" -> "select": javafx-basic-archetype)3.1. don't forget to set the organisation name
- Download &/ copy paste an javaFx 8 class example &/ demo from somewhere, for example: http://carlfx.wordpress.com/2013/07/15/introduction-by-example-javafx-8-printing/4.1. Now set the project sources to 1.8 and utf-8
- Clean and build and run it!
- enjoy!
万一您无法从控制台或其他ide找到带有maven的javafx-8-lib,那么您必须像这样设置javafx-8-lib-path:
In case your are having troubles in finding the javafx-8-libs with maven from the console or with another ide, than you have to set the javafx-8-lib-path like this:
-
您必须告诉maven javafx-lib的确切位置:
You have to tell maven where the javafx-lib is exactly:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!-- this maven plugin does not functions with java 8 yet, passing java 7 is just fine. -->
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
**注意:您不必使用上面提到的特定原型即可运行它**没什么大不了的,但是下次只粘贴内容的增量而不是再次发布所有内容,如果没有增量,则工作量会更大,因为每个人都必须对文件进行比较才能理解它...
** Note: you don't have to use that specific archetype mentioned above to get it running** Nothing really bad, but next time just paste the delta of your content instead of posting all of it again, without the delta the effort is much higher, since a comparison of the file have to be made by each one trying to understand it ...
这篇关于使用Maven构建JavaFX 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!