0

I am learning Spring Boot. I have just created my first project using maven, Spring Boot, Spring Rest support and MongoDB. It compiles successfully, but it resolves all the dependencies, but do not compile the java classes at all.

After compilation, jar file is correctly created, it contain lib folder, metadata etc, but it do not contain project class file at all.

Hence when i run the project with mvn spring-boot:run, it throws an exception that class not found (Main method class for Spring boot initialization).

Please suggest, what I am doing wrong here, here is my maven configuration class:

 <?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>

<properties>
    <java.version>1.6</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <start-class>com.assignment.BootInitializer</start-class>
</properties>


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

<groupId>com.assignment</groupId>
<artifactId>spring-assignment</artifactId>
<version>1.0</version>
<packaging>jar</packaging> 

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

</dependencies>

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

</project>

And here is the main initializer class:

    package com.assignment;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class BootInitializer {

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

What I need to do, to ensure that maven is compiling the java classes and including them in the jar file.

Thanks.

  • start with a basic project like https://projects.spring.io/spring-boot/ and try to run it, if everything goes fine add new functionality step by step with frecuent compilations – jmhostalet Sep 27 '17 at 14:46
  • question is why java code is not getting compiled... – Athir Gillani Sep 27 '17 at 15:48
  • Here is the example like what you are doing http://javabycode.com/spring-framework-tutorial/spring-boot-tutorial/spring-boot-restful-web-services-example.html – David Pham Sep 28 '17 at 04:03

1 Answers1

0

I am learning Spring Boot.

Okay, good. Let's do one step at a time. Go to start.spring.io and generate a template project with whatever dependencies you want and whatever build tool (maven / gradle) you like. Build it and run it and see whether it is coming up or not. Then incrementally build on top of it.

so-random-dude
  • 15,277
  • 10
  • 68
  • 113