当前位置: 首页 > 知识库问答 >
问题:

Javafx项目不能用maven编译

夏烨霖
2023-03-14

我有一个Java FX项目,正在使用maven 3.0.5进行构建。当我运行mvn package/install时,项目失败并抱怨包javafx.*不存在。据我所知,Javafx是用Java1.7封装的,所以构建过程中不采用这一点是没有意义的。当我在IDE(intellij)中编译它时,它工作得很好,然后我的maven构建也成功安装了,但是我不希望每次进行干净的安装时都要经历IDE。有什么想法吗?

<?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">
    <parent>
        <artifactId>thenaglecode</artifactId>
        <groupId>com.thenaglecode</groupId>
        <version>1.0.0.Pre-Alpha</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>system-setup</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-vfs2</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <includeEmptyDirs>true</includeEmptyDirs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.5.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>gui</headerType>
                            <jre>
                                <path>C:\Program Files\Java\jre7</path>
                                <minVersion>1.7.0</minVersion>
                                <initialHeapSize>128</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                            <jar>${project.build.directory}/${project.build.finalName}.jar</jar>
                            <outfile>${project.build.directory}/systemsetup.exe</outfile>
                            <classPath>
                                <mainClass>com.thenaglecode.Start</mainClass>
                            </classPath>
                            <singleInstance>
                                <mutexName>thenaglecode-system-setup</mutexName>
                            </singleInstance>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/CommandHelper.java:[3,26] package javafx.application does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/ListAndOptionsController.java:[3,26] package javafx.beans.value does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/ListAndOptionsController.java:[4,26] package javafx.beans.value does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/ListAndOptionsController.java:[5,26] package javafx.collections does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/ListAndOptionsController.java:[6,20] package javafx.event does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/ListAndOptionsController.java:[7,20] package javafx.event does not exist
...
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/Context.java:[3,28] package javafx.scene.control does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/ServiceMuncher.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/TypeInfo.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/NumericOnlyTextFieldChangeListener.java:[3,31] package com.sun.istack.internal does not exist
[ERROR] /C:/Users/Macindows/IdeaProjects/thenaglecode/system-setup/src/main/java/com/thenaglecode/NumericOnlyTextFieldChangeListener.java:[4,26] package javafx.beans.value does not exist
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

谢谢你的帮助。

共有1个答案

太叔英卫
2023-03-14

将其放在依赖项中(取决于jdk所在的位置)将有助于编译依赖项,但是您可能应该用一个用户可以在settings.xml或maven系统属性中指定的变量来替换它:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>javaFX</artifactId>
        <version>2.2</version>
        <scope>system</scope>
        <systemPath>C:\Program Files\Java\jre7\lib\jfxrt.jar</systemPath>
    </dependency>

有关原因的更多细节,请参见使用JavaFX的Maven project(在'lib'中使用jar文件)

 类似资料:
  • 我正在用Java编写一个程序,并且使用JavaFX作为GUI。直到今天,我一直在使用javafx独立编写代码,所有的事情都运行得很顺利。我已经决定开始使用maven,现在项目不编译,也不运行或执行。 这是我的主要课程: 我在其他项目中使用过maven,但从未使用过JavaFX。我该怎么办?

  • 问题内容: 我有一个Java FX项目,正在使用maven 3.0.5进行构建。当我运行mvn package / install时,项目失败,并抱怨该包javafx。 * 不存在。据我了解,Javafx是用Java 1.7打包的,因此该构建没有接受它是没有意义的。当我在IDE(intellij)中编译它时,它可以正常工作,并且之后我的maven构建也成功安装,但是我不希望每次执行全新安装时都必须

  • 我在我的项目中使用jpl库时遇到了一个问题。 奇怪的是,在一个老项目上,它是一个普通的Java应用程序,通过遵循这个解决方案jpl/SWI Prolog配置失败,它可以很好地与jpl库工作。该解决方案提到,我必须配置环境变量,以便使库与Java对话。 另一方面,我的新项目是一个maven项目。首先,我包含了Maven的以下依赖关系。 但我得到了以下例外情况: 有什么我能做的吗?

  • 我已经将Jitpack repo和依赖项从Github添加到pom中。但它仍然无法编译。然而,当我指向导入块中的行时,它清楚地显示了模块的描述。VSCode截图 例如,我尝试导入com.github.kwhat.jnativehook.GlobalScreen,它显示了模块的描述,但仍然用红色下划线并显示错误: 类型为com。github。科哈特。jnativehook。无法通过Java访问Glo

  • 我正在做一个类项目,需要使用Maven作为JavaFx项目的构建工具。 这是我的pom.xml设置,我在其中使用了2个插件。根据我的理解:是强制java jdk 1.8作为编译器,是自动下载javafx库。 另外,我的主启动器main.java文件位于。与文件夹处于同一级别。 然而,编译总是失败。 我不知道哪一步错了...任何想法都将不胜感激。

  • 我有一个使用Maven、JPA和JavaFX的项目。我在maven中执行安装。一切都很顺利。但是当我运行jar文件时,我得到了带有异常的堆栈跟踪。 pom。xml 也是我的StackTrace 我在谷歌上搜索了这个问题,但没有找到对我有帮助的东西。 若我在引用DB的代码中注释了两行,那个么应用程序就会启动。好吧。我的应用程序找不到持久性类。我做错了什么?