0

Within Eclipse I am able to run a Spring Boot application using Run As > Java Application > Application - xxx where xxx = projectname. Using this way to run the application works. Started Application in 5.091 seconds (JVM running for 5.445)

Now as this is working, I want to be able to run the application outside Eclipse. Is this possible?

What I have tried

I made an application build file using Run As > Maven install. This fills up the target folder with among other things a project-0.0.1-SNAPSHOT.jar and project-0.0.1-SNAPSHOT.jar.original file.

I searched over the internet and found that it is possible to run those files using java -jar project.jar. Unfortunatelly this gives the following error output:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

Question

Does anybody know another way to run the Spring Boot application outside Eclipse or know how to fix this error?

Klyner
  • 3,983
  • 4
  • 26
  • 50
  • it should work if you do `java -jar project-0.0.1-SNAPSHOT.jar`. if you have any profile, application variables which has to set by starting the app, you have to set those, too. Look at your stacktrace – Patrick Oct 20 '17 at 11:56
  • the error message lets assume, that you are missing some "db configuration" (properties or dependencies ... which is available in your eclipse rt but not in the packaged jar/your cmd invocation ...`spring.datasource.*`) ...but it can also be connected to `spring.profiles.active` ...and of course the details of the maven buid are relevant.. – xerx593 Oct 20 '17 at 11:59
  • This is already answered [here in stackoverflow](https://stackoverflow.com/questions/24074749/spring-boot-cannot-determine-embedded-database-driver-class-for-database-type). Ensure that application.properties contains `pring.datasource.url = … spring.datasource.driver-class-name = …` . Place the properties file inside target folder. – Bharanidharan K Oct 20 '17 at 12:03
  • @BharaniK Locally I already added the right spring.datasource.url. Should this addition be ok: spring.datasource.driver-class-name=com.mysql.jdbc.Driver? Or with other spelling? – Klyner Oct 20 '17 at 12:06
  • @Klyner, If I were you, I would analyze following. 1. Ensure that application.properties is picked up by application. 2. Potential chance that springboot's autoconfiguration might conflict. Explicitly exclude springboot's datasource autoconfigruation by adding following line in application.properties `spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration` . – Bharanidharan K Oct 20 '17 at 12:15

2 Answers2

3

You don't have an embedded datasource available/on the classpath at runtime.

Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

See this documentation, https://docs.spring.io/spring-boot/ocs/current/reference/html/boot-features-sql.html

Adding your preferred embedded database should allow it to start. e.g.,

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54
  • This helped for me so far that the Tomcat server is running! Unfortunatelly it stucks at a database request. Also, where Eclipse prints debug data, the console doesn't do that. The corresponding frontend application is not able to FETCH data from the database. – Klyner Oct 20 '17 at 13:50
  • Ok, however the application is now starting. I'd recommend you review the errors and try to determine what the new issue is. – Darren Forsythe Oct 21 '17 at 00:02
0

Eclipse is irrelevant; you should know how to run a Spring Boot executable JAR without an IDE. You won't be deploying that IDE.

I'll guess that you really have a packaging issue. The executable JAR does not have all its dependent JARs inside.

Use the Maven Shade plug-in to create a fat JAR for you.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I have tried this using this tutorial: https://maven.apache.org/components/plugins-archives/maven-shade-plugin-LATEST/usage.html. First I copied the Shade plugin configuration into my pom file (without configuration tagg content). Then I executed mvn package which generated two jar files. (original-project.jar and project.jar) Running those with `java -jar` results in java.lang.IllegalStateException: Unable to open nested entry 'lib/h2-1.4.192.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file – Klyner Oct 20 '17 at 14:08