I'm not sure why I am having this issue. Here's what I'm running on linux command line:
sudo java -jar gs-rest-service-0.1.0.jar -cp ./hello
java.lang.ClassNotFoundException: hello.Application
sudo java -jar gs-rest-service-0.1.0.jar -cp hello
java.lang.ClassNotFoundException: hello.Application
Tried it both ways, with the ./ and without. Also tried it like this:
sudo java -jar gs-rest-service-0.1.0.jar -cp ./main/java/hello
java.lang.ClassNotFoundException: hello.Application
Again with and without the ./. When I view the jar file I see the Application.class file in main/java/hello all lower case. Here's my MANIFEST.MF
Manifest-Version: 1.0
Class-Path: ./hello
Update: Got it working. Here I had an issue in my pom.xml file I had specified start-class as hello.Application but my package names I kept messing around with so they were never in sync and adding the -cp wasn't helping since now I would have package one thing in the classes, start-class in the pom.xml another, and -cp even in the wrong location on the command line! Argh.. Just a dumb night.
Here's the working code:
pom.xml
<?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>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.0.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<properties>
<start-class>main.java.hello.Application</start-class>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/libs-snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Application.java:
package main.java.hello;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
All other java files have the same package name specified and used in the eclipse IDE. To get rid of the IDE showing red X's on everything I ran maven with this param:
mvn dependency:copy-dependencies
As described in this wonderful question here:
Downloading all maven dependencies to a directory NOT in repository?
After downloaded I created a user library and pulled all jar files from the dependency directory that's created after maven does it's download thing. Thought I'd add that into the question. A bit out of scope but was helpful to get rid of further errors in the IDE that show up when editing a stupid simple hello world web service.