0

I have migrated my project from gradle 5 to 7.1 and spring boot 2.5.3. After i build the jar, i tried to execute the same. Earlier it was working fine. But now, its not detecting the application.properties file. I have tried many solutions in Stackoverflow and other website, but it didn't help me. It would be very helpful if anyone can point out my mistake. Am trying to execute in windows machine. application.properties file is present inside config folder which is parallel to jar

Attempt 1:

java -Dloader.path=.,config\ -jar xyz-1.0.0.jar

error :

class path resource [application.properties] cannot be opened because it does not exist

Attempt 2:

java -Dspring.config.location=classpath:/application.properties -jar xyz-1.0.0.jar

error :

ConfigDataResourceNotFoundException: Config data resource 'class path resource [application.properties]' via location 'classpath:/application.properties' cannot be found

Attempt 3:

java -jar xyz-1.0.0.jar -Dspring.config.location=classpath:/application.properties

error :

 FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist

Attempt 4:

java -Dspring.config.location=file:c:\Sheljith\tools\config\application.properties  -jar xyz-1.0.0.jar

error :

FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist

Attempt 5:

java --spring.config.location=file:c:\Sheljith\tools\config\application.properties  -jar xyz-1.0.0.jar

error :

Unrecognized option: --spring.config.location=file:c:\Sheljith\tools\config\application.properties

Attempt 6:

java -Dspring.config.name=application -Dspring.config.location=file:///C:/Sheljith/tools/drc-reports-generator/config/ -jar xyz-1.0.0.jar

error:

.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist

Attempt 7:

java -Dspring.config.location=file:///C:/Sheljith/tools/config/application.properties -jar xyz-1.0.0.jar

error:

class path resource [application.properties] cannot be opened because it does not exist

build.gradle

    buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin")
    }
}
plugins {
    id 'org.springframework.boot' version '2.5.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}
jar.archiveName = "drc-reports-generator.jar"
version = '1.0.0'
sourceCompatibility = '1.8'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                   'Implementation-Version': version
    }
}



repositories {
    mavenCentral()
    mavenLocal()
}
processResources{
    exclude '*/**'
}

springBoot{
    mainClass = "com.xyz.Application"
}

dependencies {
    implementation group: 'commons-collections', name: 'commons-collections', version: '3.2'
    implementation("org.springframework.boot:spring-boot-starter") 
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    testImplementation group: 'junit', name: 'junit', version: '4.+'
    testImplementation group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.13.1'
    implementation 'com.itextpdf:itextpdf:5.5.11'
    implementation 'org.springframework:spring-web:4.3.6.RELEASE'
    implementation 'com.microsoft.sqlserver:sqljdbc4:4.0'
    implementation("com.h2database:h2")
    implementation("org.apache.commons:commons-lang3:3.0")
    implementation group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '3.0.0'
}

test {
    useJUnitPlatform()
}
  • Can you share the pom.xml related changes you did as part of your migration? – vaibhavsahu Aug 25 '21 at 16:09
  • can you try application.yml file for storing your project configs? – vaibhavsahu Aug 25 '21 at 16:14
  • @vaibhavsahu, i am using gradle, have added my build.gradle to the question – Sheljith krishnan Aug 25 '21 at 16:14
  • @vaibhavsahu Thanks for the quick response. we are following the .properties across all the tools. We can change it only as last option. – Sheljith krishnan Aug 25 '21 at 16:15
  • If it is parallel (so next to your jar file) you don't need to do anything as that is a [standard location](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files) scanned already by Spring Boot. UNrelated but a source for trouble you are mixing jars from different versions of Spring. Spring web 4.x isn't compatible with Spring Boot 2.5 (remove the version so the correct one is included). – M. Deinum Aug 26 '21 at 05:07

1 Answers1

0

Since the application.properties file is located in parallel to the jar file. try this:

java -jar xyz-1.0.0.jar --spring.config.location=application.properties

Edit: Can you try this once:

java -Dspring.config.additional-location=application.properties -jar xyz-1.0.0.jar

change existing processResources to below: // Exclude all resources from the jar

jar {
    processResources.exclude('*')
}
Arun Sai Mustyala
  • 1,736
  • 1
  • 11
  • 27
  • actually the config folder is parallel to jar and the config folder was containing the application.properties. But for testing this, i copied the properties to same folder as that of jar and tried. But same result. "FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist" – Sheljith krishnan Aug 25 '21 at 16:30