Recommand · October 14, 2021 0

reference a conf file in assembly jar

I have a problem in a fat jar when I try to reference configuration files:

My plugins configs

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
        <!-- Delivery assembly -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <finalName>prd-assembly-${project.version}</finalName>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <attach>false</attach>
                <archive>
                    <manifest>
                        <mainClass>com.prd.Main</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

after mvn clean package I get the assembly with application.conf at the root and then folders starting with com…

then in my code I have the following:

   import com.typesafe.config.ConfigFactory

   File configurationFile= new File("application.conf")
   ConfigFactory.parseFile(configurationFile)

but when I execute I have :

 2021-10-14 14:08:41 WARN  NativeCodeLoader:62 - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

 application.confException in thread "main" com.typesafe.config.ConfigException$Missing: 

 No configuration setting found for key 'app'

My first assumption was that my file path is not good, but not sure.