我想以intellij的想法运行一个演示春季启动应用程序,但是我遇到了错误:
Error:(3, 32) java: package org.springframework.boot does not exist
我的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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.21.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>helloworld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>helloworld</name>
<description>Hello World project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:0)
确保打开pom.xml而不是打开文件夹。 IntelliJ将询问您是否要导入为项目。对这个问题回答是。 您始终可以右键单击pom.xml,然后选择Maven-> Reimport,它将自动为您创建类路径。
然后从树中转到主类,然后右键单击并选择“运行”。那应该在您的运行配置中创建一个临时配置。
其余的您可以在这里找到:
https://www.jetbrains.com/help/idea/running-applications.html
如果要作为Maven项目运行,请执行以下操作:
https://www.jetbrains.com/help/idea/work-with-maven-goals.html
如果要以Java jar从终端运行,则在构建spring-boot-jar时,按CTRL + TAB + T(激活终端)并输入终端:
java -jar target/yourjar.jar
答案 1 :(得分:0)