spring - java.lang.ClassNotFoundException even though I specify -cp argument to the class file -


i'm not sure why having issue. here's 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 both ways, ./ , without. tried this:

sudo java -jar gs-rest-service-0.1.0.jar -cp ./main/java/hello java.lang.classnotfoundexception: hello.application 

again , without ./. when view jar file see application.class file in main/java/hello lower case. here's manifest.mf

manifest-version: 1.0 class-path: ./hello 

update: got working. here had issue in pom.xml file had specified start-class hello.application package names kept messing around never in sync , adding -cp wasn't helping since have package 1 thing in classes, start-class in pom.xml another, , -cp in wrong location on command line! argh.. dumb night.

here's 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 same package name specified , used in eclipse ide. rid of ide showing red x's on ran maven param:

mvn dependency:copy-dependencies 

as described in wonderful question here:

downloading maven dependencies directory not in repository?

after downloaded created user library , pulled jar files dependency directory that's created after maven it's download thing. thought i'd add question. bit out of scope helpful rid of further errors in ide show when editing stupid simple hello world web service.

you need specify main class.

sudo java -cp gs-rest-service-0.1.0.jar -cp ./main/java hello.application 

the -jar flag tells java run main class referenced in jar.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -