IntelliJ – JavaFX and JavaDoc: 两个版本的模块

huangapple go评论67阅读模式
英文:

IntelliJ - JavaFX and JavaDoc: Two versions of module

问题

我在为一个 JavaFX 项目设置 IntelliJ 时遇到了一些困难。
我使用了 文件 > 项目结构 > 库 > 添加新库 > 来自 Maven,搜索 org.openjfx:javafx-fxml:11.0.2 进行了设置。所以它被找到了,我还特意勾选了 下载 JavaDocs,因为这会很有用。

然而,当我尝试启动项目时,我得到了以下错误:

> java.lang.module.FindException: 在 lib 中找到了两个版本的 javafx.graphics 模块 (javafx-graphics-11.0.2-linux.jar 和 javafx-graphics-11.0.2-javadoc.jar)

显然编译器误将 javadoc 当作另一个版本...

然后我移除了为 JavaFX 下载的 *javadoc.jar 文件,程序就可以正常启动了。
正如你可以想象的,我希望能够在我的 IDE 中直接阅读 JavaDoc。

有任何修复这个问题的想法吗?

编辑:
这里有一个 Github 上的示例仓库:
leun4m/javafx-demo@2a7a03a

运行配置:

--module-path lib --add-modules javafx.controls,javafx.fxml
英文:

I got a bit of a struggle setting up IntelliJ for a JavaFX project.
I set it up using File > Project Structure > Libraries > Add new library > From Maven searching for org.openjfx:javafx-fxml:11.0.2. So it was found and I deliberately checked Download JavaDocs since this would be useful.

However, when I tried to start the project, I got the following error:

> java.lang.module.FindException: Two versions of module javafx.graphics found in lib (javafx-graphics-11.0.2-linux.jar and javafx-graphics-11.0.2-javadoc.jar)

Apparently the compiler mistoke javadoc for another version...

When I then removed the *javadoc.jar files downloaded for JavaFX the program started just fine.
As you can imagine, I would like to keep the possibility to read JavaDoc directly in my IDE.

Any ideas how to fix that?

Edit:
Here is a sample repo at Github:
leun4m/javafx-demo@2a7a03a

Run Configuration:

--module-path lib --add-modules javafx.controls,javafx.fxml

答案1

得分: 1

我成功地通过以下步骤使您的项目编译、运行并获取了文档:

  1. 在根目录下添加了一个 pom.xml 文件:
<?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>org.example</groupId>
    <artifactId>java-fx-pom</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.13</java.version>
        <maven.compiler.source>13</maven.compiler.source>
        <maven.compiler.target>13</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  1. 使用 mvn clean install 进行构建。
  2. 使用 javafx:run -f pom.xml 运行。
  3. 要获得更好的文档,您需要"进入"任何 JavaFX 方法,可以通过将光标放在方法上,然后按下 Ctrl+B,并点击 "Download Sources"。
  4. 最后,我已经为您的测试仓库创建了一个 PR。我有意推送了一些 Idea 文件,这应该会减少您收到的错误数量。
英文:

I managed to make to compile, run and get docs in your project by doing next:

  1. Adding a pom.xml to the root:

    <?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&quot;>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>java-fx-pom</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
    <java.version>1.13</java.version>
    <maven.compiler.source>13</maven.compiler.source>
    <maven.compiler.target>13</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11.0.2</version>
    </dependency>
    <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11.0.1</version>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.3</version>
    <configuration>
    <mainClass>Main</mainClass>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>

  2. building with mvn clean install

  3. running with javafx:run -f pom.xml

  4. to get better docs you need to go "inside" any javafx method, you can do that by putting cursor and pressing Ctrl+B, and click on "Download Sources"

  5. Finally I've created a PR to your test repository. I've intentionally pushed some idea files, that should reduce amount of errors you get.

答案2

得分: 0

如果你处于特殊情况,无法使用任何构建工具,比如Maven或者Gradle,最近有人给我展示了一个解决方法:

  1. 进入项目结构 > 全局库
  2. 添加库
    • 确保取消勾选下载到,或者选择与lib/不同的目录
    • 勾选源代码和/或Java文档(根据你的需求)

通过这种方式,项目可以像以前一样运行,但是IntelliJ可以在不涉及构建和执行应用程序方面的任何冲突的情况下,向你展示已导入库的文档甚至源代码。

IntelliJ现在将把项目中的库列为一个问题,因为它实际上是重复的。然而,这不是一个问题,因为通过运行配置,lib目录仍然会用于执行项目。

英文:

In case you're in the special situation where you can't use any build tools like Maven or Gradle, someone recently showed me a workaround:

  1. Go to Project Structure > Global Libraries
  2. Add the library
    • make sure you uncheck Download to or select a different directory than lib/
    • check sources and or javadoc (depending on your needs)

This way the project can be run like before, but IntelliJ can show you the documentation or even the source code of the imported library without any conflicts regarding building and executing the application.

IntelliJ will now list as a problem, that the library in the project itself is no longer needed (since it's in fact duplicated now). However, this is not a problem since the lib directory will still be used for executing the project via the run configuration.

huangapple
  • 本文由 发表于 2020年9月16日 17:11:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63916806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定