如何使用我用 Maven 导入的依赖?

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

How to use a dependency that I imported with Maven?

问题

我将这个依赖项添加到我的项目中,以便我可以使用 WebClient 类:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
    <version>2.3.2.RELEASE</version>
</dependency>

我运行了 mvn clean install -U 命令,它成功下载了依赖项。然后我关闭了 IntelliJ,并重新打开了它。IDE 顺利识别了这个依赖项。然而,我无法弄清楚如何在我的代码中实际使用它...

如果我这样做:WebClient webClient = new WebClient(); 它会抱怨无法“解析符号”WebClient,也不会建议我导入它。我尝试手动导入 import org.springframework.boot.*;,但仍然无法识别该符号。你有关于如何解决这个问题的任何提示吗?

module-info.java

module org.openjfx {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.sql;

    opens agill.deshopp to javafx.fxml;
    opens agill.deshopp.controllers to javafx.fxml;
    opens agill.deshopp.components to javafx.fxml;

    exports agill.deshopp;
}

pom.xml

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>agill.deshopp</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>11</maven.compiler.release>
        <javafx.version>13</javafx.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.32.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <version>2.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectreactor</groupId>
            <artifactId>reactor-spring</artifactId>
            <version>1.0.1.RELEASE</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>${maven.compiler.release}</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>agill.deshopp.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
英文:

I added this dependency to my project so I could use the WebClient class:

&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-webflux&lt;/artifactId&gt;
&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;/dependency&gt;

I ran mvn clean install -U and it download the dependency successfully. Then I closed IntelliJ and opened it again. The IDE recognized the dependency smoothly. However, I can't figure out how to actually use it in my code...

If I do: WebClient webClient = new WebClient(); it just complains that it cannot resolve symbol &quot;WebClient&quot;, it doesn't suggest me to import it. I tried importing manually with import org.springframework.boot.*;, but still doesn't recognize the symbol. Any tips on how I fix this?

module-info.java

module org.openjfx {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.sql;

    opens agill.deshopp to javafx.fxml;
    opens agill.deshopp.controllers to javafx.fxml;
    opens agill.deshopp.components to javafx.fxml;

    exports agill.deshopp;
}

pom.xml

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;agill.deshopp&lt;/groupId&gt;
&lt;artifactId&gt;app&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;properties&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;maven.compiler.release&gt;11&lt;/maven.compiler.release&gt;
&lt;javafx.version&gt;13&lt;/javafx.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-controls&lt;/artifactId&gt;
&lt;version&gt;${javafx.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-fxml&lt;/artifactId&gt;
&lt;version&gt;${javafx.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.xerial&lt;/groupId&gt;
&lt;artifactId&gt;sqlite-jdbc&lt;/artifactId&gt;
&lt;version&gt;3.32.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-webflux&lt;/artifactId&gt;
&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectreactor&lt;/groupId&gt;
&lt;artifactId&gt;reactor-spring&lt;/artifactId&gt;
&lt;version&gt;1.0.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.1&lt;/version&gt;
&lt;configuration&gt;
&lt;release&gt;${maven.compiler.release}&lt;/release&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;0.0.3&lt;/version&gt;
&lt;configuration&gt;
&lt;mainClass&gt;agill.deshopp.App&lt;/mainClass&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

答案1

得分: 1

点击IntelliJ 右侧的Maven插件中的同步按钮。这是图片中可见的第一个按钮。

如何使用我用 Maven 导入的依赖?

https://i.stack.imgur.com/ZQG7M.png

英文:

Click on the synchronise button in maven plugin on right hand side in intellij. The first Button you can see in picture.
<img src="https://i.stack.imgur.com/ZQG7M.png" width="600">
<br>
https://i.stack.imgur.com/ZQG7M.png

huangapple
  • 本文由 发表于 2020年7月26日 21:36:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63100873.html
匿名

发表评论

匿名网友

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

确定