【问题标题】:Maven: How do I use JMetro styling with Maven?Maven:如何在 Maven 中使用 JMetro 样式?
【发布时间】:2020-02-03 10:32:13
【问题描述】:

我想在我的 Maven 项目中使用 JMetro 样式,但无论我做什么,Maven 都会给我同样的错误。我正在使用来自org.openjfx 的javafx-archetype-simple,我尝试通过将其作为依赖项添加到我的pom.xml 中来使用JMetro,并通过将.settings.xml 添加到~/.m2/ 来从JCenter 下载它。每当我在mvn clean 之后尝试做mvn javafx:run 时,我总是会收到这个错误:

[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< io.colocasian.calc:ore-no-calculator >----------------
[INFO] Building ore-no-calculator 1.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> javafx-maven-plugin:0.0.4:run (default-cli) > process-classes @ ore-no-calculator >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ore-no-calculator ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/rishvic/Documents/Java/ore-no-calculator/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ore-no-calculator ---
[WARNING] Can't extract module name from jmetro-11.6.5.pom: zip END header not found
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /home/rishvic/Documents/Java/ore-no-calculator/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[17,22] package jfxtras.styles does not exist
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[35,26] cannot find symbol
  symbol:   class Style
  location: class io.colocasian.calc.App
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[35,40] cannot find symbol
  symbol:   variable Style
  location: class io.colocasian.calc.App
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[377,13] cannot find symbol
  symbol:   class JMetro
  location: class io.colocasian.calc.App
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.443 s
[INFO] Finished at: 2020-01-31T21:46:28+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ore-no-calculator: Compilation failure: Compilation failure:
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[17,22] package jfxtras.styles does not exist
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[35,26] cannot find symbol
[ERROR]   symbol:   class Style
[ERROR]   location: class io.colocasian.calc.App
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[35,40] cannot find symbol
[ERROR]   symbol:   variable Style
[ERROR]   location: class io.colocasian.calc.App
[ERROR] /home/rishvic/Documents/Java/ore-no-calculator/src/main/java/io/colocasian/calc/App.java:[377,13] cannot find symbol
[ERROR]   symbol:   class JMetro
[ERROR]   location: class io.colocasian.calc.App
[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

链接到Gist 包含我编辑的pom.xml、settings.xml 和App.java,我曾经尝试在我的项目中使用JMetro。源代码(不含 JMetro,实际使用 mvn clean javafx:run 运行)linked here。

java -version 的输出:

openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10)
OpenJDK 64-Bit Server VM (build 11.0.6+10, mixed mode)

mvn --version 的输出:

Apache Maven 3.6.3 (NON-CANONICAL_2019-11-27T20:26:29Z_root)
Maven home: /opt/maven
Java version: 11.0.6, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.15-2-manjaro", arch: "amd64", family: "unix"

PS:我对使用 Maven 真的很陌生,我非常感谢一些关于使用 Maven 的建议,一般来说,以及在其上使用 JavaFX。最初,在Github Issues、JFXtras Styles Git repo 上发布了这个问题,但这并不是 JMetro 本身的问题,所以在这里发布了这个问题。

额外信息:我不知道这是否与它有关,但我仍然将其添加为参考。当我将 JMetro 11.6.7 添加为依赖项并重新运行 mvn clean javafx:run 时,在下载时,它给了我这些警告,

...
[WARNING] Can't extract module name from jmetro-11.6.7.pom: zip END header not found
...
[WARNING] Can't extract module name from jmetro-11.6.7.pom: Only outputDirectories and jars are accepted on the path
[WARNING] Some dependencies encountered issues while attempting to be resolved as modules and will not be included in the classpath; you can change this behavior via the  'includePathExceptionsInClasspath' configuration parameter.

【问题讨论】:

  • 我认为你的导入是错误的。也许您可以尝试使用import jfxtras.styles.jmetro.*; 导入星号。
  • 我试过了。没用。
  • 我不太确定是否需要额外的存储库,JMetro 似乎位于 Maven 中心。在任何情况下,您都不需要或不应该编辑您的 settings.xml,您可以直接在 pom 本身中声明项目需要的任何额外存储库。 maven.apache.org/pom.html#Repositories
  • 我尝试在不将settings.xml 添加到我的~/.m2/ 文件夹的情况下运行,但它找不到对Maven Central 的依赖。似乎创建者忘记将其添加到 Maven Central 存储库(此处链接:github.com/JFXtras/jfxtras-styles/issues/…)。而且我认为这不应该对这个特定问题做任何事情。
  • @A-Warm-Jicama 如果 repo 无法正常运行并给你一个无法正常工作的 pom,它会这样做。

标签: java maven javafx


【解决方案1】:

JMetro 的官方 Maven 存储库也不适合我。我求助于从 GitHub 下载 JMetro jar,手动将其添加到 Maven,然后在我的 JavaFX 应用程序中使用它。

以下是我为使 JMetro 与 Maven 更好地配合所做的工作:

  1. 从GitHub下载官方JMetro jar

  2. 将下载的jar添加到本地Maven repo:

    mvn install:install-file -Dfile=jmetro-11.6.15.jar -DgroupId=com.jfxtras -DartifactId=jmetro -Dversion=11.6.15
    
  3. 将其作为依赖项添加到项目的pom.xml:

    <dependency>
        <groupId>com.jfxtras</groupId>
        <artifactId>jmetro</artifactId>
        <version>11.6.15</version>
    </dependency>
    
  4. 对于模块化项目,请在项目的module-info.java 中声明:

    module <ModuleName> {
        ...
        requires org.jfxtras.styles.jmetro;
        ...
    }
    

现在JMetro可以正常使用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多