0

I am ready for this to be a newbie question, apologies in advance!

I've refactored my project from an example "first look at restful/spring" type exercise into a customised application. Somewhere along the way I've moved/deleted a reference to something and I'm now getting compilation errors like this:

/C:/<>/src/main/java/resful/layer/MuliRestfulApplication.java:[9,8] cannot access javax.servlet.ServletException class file for javax.servlet.ServletException not found

In Eclipse IDE I have a market stating: - The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files - The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files

So it looks as though I've deleted the reference to the jar that contains javax.servlet.XYZ.

Please could someone step me though how I should add the spring file into the project properly for a Restful API application? I'm not sure if I should be adding jars in a lib folder as I used to with POJOs, as spring applications manage dependencies little differently as I understand it.

I'm using Maven to build my project, I see the m2 folder with lots of jars in, see below:

I can't post images of my project organisation yet due to stackoverflow police FYI.

And help MUCH appreciated.

Matt

Here's my pom.xml file:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>org.springframework</groupId>
<artifactId>gs-consuming-rest</artifactId>
<version>0.1.0</version>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
</dependencies>


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

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

Here's my Java class file:

It's the package declaration that's giving me the error, eclipse says "The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files"

package resfullayer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class MuliRestfulApplication extends SpringBootServletInitializer{

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

    }

    // Used when deploying to a standalone servlet container
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MuliRestfulApplication.class);
    }

}

This is my build.gradle file

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-consuming-rest'
    version =  '0.1.0'
}

apply plugin: 'war'

war {
    baseName = 'muliRestfulApp'
    version =  '0.1.0'
}

task deployToTomcat(type: Copy) {
    from war
    into "C:/Users/Muli/Desktop/apache-tomcat-7.0.62/webapps"
}

repositories {
    jcenter()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

configurations {
    providedRuntime
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

}

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter")
    compile("org.springframework:spring-web")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

This is the stack trace:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-consuming-rest 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ gs-consuming-rest ---
[INFO] Deleting C:\Users\Muli\workspace\MuliAutomation\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gs-consuming-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Muli\workspace\MuliAutomation\src\main\resources
[INFO] skip non existing resourceDirectory C:\Users\Muli\workspace\MuliAutomation\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gs-consuming-rest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to C:\Users\Muli\workspace\MuliAutomation\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Muli/workspace/MuliAutomation/src/main/java/resfullayer/MuliRestfulApplication.java:[9,8] cannot access javax.servlet.ServletException
  class file for javax.servlet.ServletException not found
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.588 s
[INFO] Finished at: 2015-06-16T21:18:43+00:00
[INFO] Final Memory: 14M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project gs-consuming-rest: Compilation failure
[ERROR] /C:/Users/Muli/workspace/MuliAutomation/src/main/java/resfullayer/MuliRestfulApplication.java:[9,8] cannot access javax.servlet.ServletException
[ERROR] class file for javax.servlet.ServletException not found
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I've also noticed that the stack trace skips 2 non existent resource directories. Perhaps I've deleted this as part of the refactor (/screw up)? If so can I add it back/generate it somehow?

Matt K
  • 1
  • 1
  • 3
  • You cannot post images... but a code sample would helps people to understand what you're asking here. – рüффп Jun 15 '15 at 22:44
  • I've added the code and pom.xml file. Could it be that the pom.xml file contains the indirect reference to the missing jar/library that contains Servlet classes? Thanks for any help! – Matt K Jun 16 '15 at 19:56
  • Please could someone point me in the right direction here? – Matt K Jun 19 '15 at 10:42
  • Did you check the duplicate link? If it does not solve your problem, just update your pom.xml from your question. – рüффп Jun 19 '15 at 12:19
  • Thanks, it was the missing reference in the pom file, somehow it was deleted when I was re-factoring the project. The link provided to answer to my question. Thanks again! – Matt K Jun 28 '15 at 10:33

0 Answers0