英文:
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:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
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 "WebClient"
, 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
<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>
答案1
得分: 1
点击IntelliJ 右侧的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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论