问题描述
我按照,最终得到了一个有几个问题的Eclipse项目。第一个问题是,当我右键单击包含main条目方法的类并选择Run As选项时,我得到的唯一条目是回退Run Configurations ...方法。我既没有选择将它作为Spring Boot App或Java Application运行。
I followed the instructions in Spring Boot Support in Spring Tool Suite 3.6.4 and ended up with an Eclipse project which has several issues. The number one issue is that when I right-click on the class containing the "main" entry method and select the "Run As" option, the only entry I get is the fallback "Run Configurations..." method. I neither get the option to run it as a "Spring Boot App" or as a "Java Application".
我的问题是如何创建项目或者做什么我是按照该网站的说明创建的,以获得Run As选项吗?
My question is how do I create the project or what do I do after it's created following the instructions in that site to get that Run As option?
除上述信息外,我还应添加以下内容:
In addition to the above information, I should add the following:
- 我正在使用Eclipse 4.4.2(Luna SR2)和STS 3.7.1
- 我试过了它在Windows和Linux上(Fedora with OpenJDK)
- 使用Java 8(Sun Hotspot 64位1.8.0_65)
-
pom.xml最初被创建,它有一个错误显然是由于m2e想要的配置丢失我需要添加以下内容:
- I'm using Eclipse 4.4.2 (Luna SR2) and STS 3.7.1
- I've tried it on both Windows and Linux (Fedora with OpenJDK)
- Used Java 8 (Sun Hotspot 64-bit 1.8.0_65)
When the pom.xml initially gets created, it has an error apparently due to a missing config the m2e wants for which I needed to add the following:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[3.1,)</versionRange>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
看起来Eclise项目也没有为Java应用程序正确配置。 Java src树没有配置。以下是.project文件:
It doesn't look like the Eclise project is properly configured for a Java application either. There's no configuration for a Java src tree. Below is the .project file:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>demo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
推荐答案
要在sts中创建一个新的spring-boot项目,只需单击新的spring-starter项目,即可为您创建项目。
New-> Project-> Spring-> Spring starter project
To create a new spring-boot project in sts just click new spring-starter project, that will create the project for you.New->Project->Spring->Spring starter project
您将通过向导选择Web复选框以选择Web应用程序
这将创建一个这样的应用程序类
You'll run throught the wizard select 'Web' checkbox to have the web app selectedthis will create an application class like this
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
我自动生成的POM
<?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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
这篇关于如何在Eclipse中创建一个使用运行配置正确配置的Spring Boot Starter项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!