0

I am not able to run a spring boot application (main class) from UNIX using putty with could not find or load main class error.

All files are given 0755 executable permissions under the project folder. Tried using command: java -cp .:batch-services.jar:lib/* com.spring.integration.demo.SpringBootDemoApplication

Running command from the path: /app/batch

Folder structure in UNIX:

/app/batch/lib - this folder has all the dependency jars

/app/batch/batch-services.jar

Expected result is that the spring boot application will start successfully.

Actual result is:

Error: Could not find or load main class com.spring.integration.demo.SpringBootDemoApplication

devlperMoose
  • 305
  • 1
  • 3
  • 14
  • 1
    Why don't you just package it using SpringBoot and turn executable mode on? – Boris the Spider Jan 28 '19 at 21:41
  • @devlperMoose - as Mateusz Stefek said, you need to build your Spring Boot app as a "fat jar", then run it over putty as described in the link about. Please consider upvoting and accepting Mateusz Stefek's reply, if it helped you. – paulsm4 Jan 28 '19 at 22:13
  • @paulsm4 your duplicate was about attaching child processes to the SSH shell session; which where therefore dying when the session was closed. Rather unrelated to this question. – Boris the Spider Jan 29 '19 at 20:00

1 Answers1

2

It looks like you have encountered a common issue with how Java interacts with shell wildcards (asterisks). Java expects your classpath elements to be separated by colons, but your shell generates spaces.

The solution is to quote the argument. See this answer: Including all the jars in a directory within the Java classpath

Also, if you are using spring-boot, you can build your application into a so called fat-jar.

Mateusz Stefek
  • 3,478
  • 2
  • 23
  • 28