0

I created a spring boot application in intelliJ using spring initializr, after I created the project there was no run configuration found. also the DemoApplication.java file was not labeled a class in the project overview nor was it selectable when trying to use it as the main class. I found a stack overflow question(Spring Boot Program cannot find main class) that said to add the class path. when I tried it only two options show up in the drop down oracle and sun(not my class path). I then tried to mark the src folder as source root which helped make the DemoApplication visible by the spring boot configuration enter image description here

Any help on where to go next would greatly be appreciated.

here is my folder structure that was generated by the spring boot initializr. only thing i changed was making src the source root.

enter image description here

    <?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.mentor</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>2.0.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <start-class>com.</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

enter image description here

thepi
  • 342
  • 2
  • 12
  • 1
    Can you post the pom.xml file? – Minh Kieu Sep 15 '17 at 23:07
  • Reimport the Maven project, IntelliJ IDEA should configure the source root automatically. If it doesn't work, refer to http://stackoverflow.com/a/42427510/104891. The correct source root is `src/main/java`, not `src`. – CrazyCoder Sep 15 '17 at 23:22
  • That solved source root it is now 'src/main/java' problem but I am still getting 'DemoApplication is not acceptable' and error messages when trying to build. I added the error messages to the post. – thepi Sep 16 '17 at 00:26

1 Answers1

-1

Right click the pom.xml file and select 'Add as Maven' The icon on your pom.xml file should look like that:

enter image description here

Hektor
  • 1,845
  • 15
  • 19
serene
  • 1
  • As per the original question, the project is already a Maven project because the only way you have a pom.xml is by making the project as a Maven project. So how your statement answers the question. Or even if it does so, then could you please elaborate on your answer. – Varun Jain Feb 26 '20 at 04:24