首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Maven项目- java.lang.IllegalArgumentException:源代码不能为空

Spring Maven项目- java.lang.IllegalArgumentException:源代码不能为空
EN

Stack Overflow用户
提问于 2018-03-18 17:46:22
回答 2查看 2.7K关注 0票数 1

我正在尝试启动一个Spring Boot应用程序,但它无法启动。这是我的堆栈跟踪:

代码语言:javascript
复制
11:27:59.772 [main] DEBUG 
org.springframework.boot.devtools.settings.DevToolsSettings - Included 
patterns for restart : []
11:27:59.775 [main] DEBUG 
org.springframework.boot.devtools.settings.DevToolsSettings - Excluded 
patterns for restart : [/spring-boot-starter/target/classes/, /spring- 
boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, 
 /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, 
 /spring-boot-devtools/target/classes/]
11:27:59.776 [main] DEBUG 
org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs 
for reloading : [file:/C:/Users/Bobi/Documents/workspace-sts- 
3.9.2.RELEASE/springproject/target/classes/]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v2.0.0.M7)

2018-03-18 11:28:00.308  INFO 5048 --- [  restartedMain] 
o.s.boot.SpringApplication               : Starting SpringApplication 
v2.0.0.M7 on DESKTOP-MFS6ORP with PID 5048 
(C:\Users\Bobi\.m2\repository\org\springframework\boot\spring- 
boot\2.0.0.M7\spring-boot-2.0.0.M7.jar started by Bobi in 
C:\Users\Bobi\Documents\workspace-sts-3.9.2.RELEASE\springproject)
2018-03-18 11:28:00.313  INFO 5048 --- [  restartedMain] 
o.s.boot.SpringApplication               : No active profile set, falling 
back to default profiles: default
2018-03-18 11:28:01.410 ERROR 5048 --- [  restartedMain] 
o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalArgumentException: Sources must not be empty
at org.springframework.util.Assert.notEmpty(Assert.java:450) ~[spring- 
core-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:381) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at org.springframework.boot.SpringApplication.main(SpringApplication.java:1261) [spring-boot-2.0.0.M7.jar:2.0.0.M7]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher 
.java:49) [spring-boot-devtools-2.0.0.M7.jar:2.0.0.M7]

这是我的主类:

代码语言:javascript
复制
package com.example.a;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App  
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

这是我的pom.xml

代码语言:javascript
复制
<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>a</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>a</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我使用的是Spring工具套件,我通过File->New->Maven Project创建了这个项目。我在主类中添加了一些依赖项并添加了SpringApplication.run(App.class, args);行,仅此而已。我在StackOverflow上尝试了其他类似的建议,但都没有对我起作用。为了让应用程序正确启动,我必须做些什么或进行哪些更改?

EN

回答 2

Stack Overflow用户

发布于 2018-03-18 18:34:17

我解决了这个问题。我不知道我之前是如何运行这个项目的,但我只是点击->Run As->Spring Boot App,它工作正常。

票数 1
EN

Stack Overflow用户

发布于 2021-07-06 20:51:00

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49346495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档