1

This is a follow up question to this question:

java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication Maven

I have developed a web service using Eclipse on Windows. I need to run it on a Solaris station and there I get the ClassNotFoundException.

This is my pom.xml: (that maven shade plugin is something I've read about that can create an uber jar with all the dependecies).

<?xml version="1.0" encoding="UTF-8"?>

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

<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>

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

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

<properties>
    <java.version>1.8</java.version>
</properties>


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

    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>com.group.id.Launcher1</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </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>

And this is the exception I get when trying to run the jar on Solaris:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

The project got a "Maven Dependencies" folder with many jar files of the Spring framwork.

I did not really understand the answers to that question. The main answer suggested creating a consolidated jar as shown here: How can I create an executable JAR with dependencies using Maven?

But i did not fully understand how to create that conolidated jar. Do I need to add the lines in the answer to the pom file? or somewhere else? and running the mvn clean compile assembly:single should be done in windows in the command line? and if so on which path? won't just exporting to jar suffice?

If someone could make a list of operations of what to do, that'll be great.

Community
  • 1
  • 1
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

4 Answers4

1

What no one ever said in the answers to other questions is that you need to use maven to create the jar and not using Eclipse's export to jar option. What you need to do is:

1) download maven from https://maven.apache.org/download.cgi

2) The maven dir contains a 'bin' folder. Add this folder to your "path" enviornment variable (on Windows 8 right click "This PC" -> properties -> Advanced System Settings -> Environment Variables -> in System Variables find "Path" -> double click it and add it by adding the bin folder path to that variable the same way other paths are located there.

3) open CMD

4) navigate to your project's folder

5) type mvn package

The jar file is created inside the "target" folder.

Good luck

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
0

The spring-boot-maven-plugin already creates a runnable JAR with all dependencies in it when you run mvn package (this is one of the main purposes of Spring Boot). So remove the maven-shade-plugin, because this is not necessary (in fact, i think it is the real problem because it will interfere with Spring Boot).

dunni
  • 43,386
  • 10
  • 104
  • 99
  • a really noob question but.. how and where do I run the mvn package command? I tried doing it in Window's command prompt in the same folder of the pom.xml but it said that mvn is not a recognizable command – CodeMonkey Sep 17 '15 at 20:25
0

what worked for me:

  1. cd to THE_PROJECT_FOLDER via the cmd or git bash
    • mvn clean
    • maven install
    • maven package
  2. go to the project using your IDE and go to the class containing the main method
  3. Click on the @SpringBootApplication and see to the left an icon like a lamp
  4. Click on it and select download with maven
  5. Restart the server, everything is OK !!!!
FatouSeck
  • 1
  • 3
0

Adding the following plugin in pom.xml solved the issue for me:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
KayV
  • 12,987
  • 11
  • 98
  • 148