2

I'm working on an existed project, it should be working ok with no problems, the first step I want to do is to run it locally, but I'm having this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    SpringApplicationBuilder cannot be resolved to a type

I can't post all code cause it's very huge, but Here is the code that is causing the error, with the author note:

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

/**
 * The main application class which bootstraps all configuration and runs the
 * application. This class can be run standalone (e.g. in Eclipse, Run As ->
 * Java Application), which start an embedded Tomcat webserver, or it can be
 * deployed as a WAR in an existing container.
 * 
 * @author
 * 
 */
@SpringBootApplication
public class Application extends SpringBootServletInitializer
{
    public static void main(final String[] args)
    {
        new SpringApplicationBuilder(Application.class).showBanner(false).run(args);
    }

And i'm doing as the author mentioned;

Eclipse, Run As -> * Java Application) ..

But getting the error above, what I'm doing wrong? I cloned all project, maybe I'm missing some library package? shouldn't be in the same source where I cloned from?

Dependencies if Pox.xml:


<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring.boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>${javax.inject.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${javax.validation.api}</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>${javax.el.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>${jaxrs.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>${apache.poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${apache.poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>${apache.tika.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-parsers</artifactId>
            <version>${apache.tika.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${apache.commons.io.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>${apache.commons.validator.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${apache.httpclient.version}</version>
        </dependency>
        <dependency>
            <groupId>com.mmm.his.hdd</groupId>
            <artifactId>omicron.core</artifactId>
            <version>${hdd.omicron.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${apache.commons.lang.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- #################### -->
    <!-- Compile -->
    <!-- #################### -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>

    <!-- #################### -->
    <!-- Test -->
    <!-- #################### -->

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>
Lelo
  • 347
  • 3
  • 16
  • Can you add the link to the repo? – techtabu Jun 30 '16 at 02:37
  • Do you have required libs in your path for eclipse ? I don't use eclipse so can't help there too much, but I'd give this a try in the command line. `java -jar app.jar` once you've built it in command line of course. – waltron Jun 30 '16 at 02:43
  • @waltron, so should the author already have the requited libs in the repos? – Lelo Jun 30 '16 at 16:13
  • @techtabu, unfortunately, I can't, it's internal use – Lelo Jun 30 '16 at 16:13
  • @Lelo You will need to resolve dependencies, which sometimes can be different when building/running in your IDE than in CLI. It sounds like eclipse doesn't have all that it needs to compile. Have you tried updating all maven dependencies in your IDE (assuming you are using mvn deps) ? – waltron Jul 01 '16 at 01:18
  • @waltron, not really, I'm trying to run the exact code the author has,,, Yeah I think maven is used.. How to do that? – Lelo Jul 01 '16 at 15:01
  • @Lelo you could try this, http://stackoverflow.com/questions/20546962/what-does-maven-update-project-do-in-eclipse – waltron Jul 03 '16 at 02:42

2 Answers2

2

One Possible solution: In your pom.xml add the following dependencies:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
  • So XML is important? I thought it does nothing,,, I'm quite new to java.. also I don't think it's missing any lines since this should be working as it is – Lelo Jun 30 '16 at 16:11
  • These are just to add the dependencies. It's quite obvious that you'd be using a build tool in your project like maven or ant. I assumed that you're using maven in your project and for that you have to add these in your pom.xml. If you're using ant, then you've to add this library in your classpath. – Raman Sahasi Jul 01 '16 at 03:35
  • I saw that similar ones are already in the pox.file, I edited my question to reflect the dependencies part of my pox file.. I'm quite new to this and not sure how java is reading those – Lelo Jul 01 '16 at 15:10
0

I've got this error after build projects.

my solution was eclipse(sts) -> project -> Clean.

hope it would be helpful.

Hajime
  • 212
  • 3
  • 13