当前位置:  开发笔记 > 编程语言 > 正文

使用Maven构建JavaFX 8

如何解决《使用Maven构建JavaFX8》经验,为你挑选了1个好方法。

我测试了使用Netbeans 7.4创建JavaFX 8项目.但遗憾的是没有运气.这是POM文件:



    4.0.0

    com.dx57dc
    JFX8M
    1.0
    jar

    JFX8M

    
        UTF-8
        com.dx57dc.jfx8m.MainApp
    

    
        
            
                org.apache.maven.plugins
                maven-dependency-plugin
                2.8
                
                    
                        unpack-dependencies
                        package
                        
                            unpack-dependencies
                        
                        
                            system
                            junit,org.mockito,org.hamcrest
                            ${project.build.directory}/classes
                        
                    
                
            
            
                org.codehaus.mojo
                exec-maven-plugin
                1.2.1
                
                    
                        unpack-dependencies

                        package
                        
                            exec
                        
                        
                            ${java.home}/../bin/javafxpackager
                            
                                -createjar
                                -nocss2bin
                                -appclass
                                ${mainClass}
                                -srcdir
                                ${project.build.directory}/classes
                                -outdir
                                ${project.build.directory}
                                -outfile
                                ${project.build.finalName}.jar
                            
                        
                    
                  
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.1
                
                    1.8
                    1.8
                    
                        ${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar
                    
                
            
        
    


当我编译jar文件时使用Netbeans 7.3.1运行它我收到此错误:

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上运行时,我得到了这个错误堆栈:

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.(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1024)
    ... 28 more

Java 8和Maven是否有任何实现并正常工作的示例?

PS 我删除插件后设法使其工作.我用这种方式编辑了POM:



    4.0.0

    com.dx57dc
    JFX8M
    1.0
    jar

    JFX8M

    
        UTF-8
        
    

    
        
            
                org.apache.maven.plugins
                maven-dependency-plugin
                2.8
                
                    
                        unpack-dependencies
                        package
                        
                            unpack-dependencies
                        
                        
                            system
                            junit,org.mockito,org.hamcrest
                            ${project.build.directory}/classes
                        
                    
                
            
            
                com.zenjava
                javafx-maven-plugin
                2.0
                
                    com.dx57dc.jfx8m.MainApp
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.1
                
                    1.8
                    1.8
                
            
        
    


它仅适用于JVM 8.我错过了POM文件中的重要内容吗?



1> 4F2E4A2E..:

JavaFx 8可以工作,只能用于Java 8.

另请查看当前的javaFx路线图:http://www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html

我没有任何问题让它运行.

    下载并安装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类示例&/ demo,例如:http://carlfx.wordpress.com/2013/07/15/introduction-by-example-javafx-8-printing/ 4.1.现在将项目源设置为1.8和utf-8

    清洁,建造并运行它!

    请享用!

如果您在从控制台或其他ide中使用maven查找javafx-8-libs时遇到麻烦,那么您必须像这样设置javafx-8-lib-path:

    你必须告诉maven javafx-lib的确切位置:

    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.1
        
                
            1.7
            1.7
            
                ${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar
            
        
    
    

**注意:您不必使用上面提到的特定原型来使其运行**没有什么不好,但下次只是粘贴内容的增量而不是再次发布所有内容,没有delta的努力是更高,因为每个人试图理解它时必须对文件进行比较......

推荐阅读
手机用户2402851335
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有