I am trying to build a fat jar file for my project. It build alright but my config file in resources folder can't be found.
this is my pom.xml
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<vertx.verticle>com.vertx.MainVerticle</vertx.verticle>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>3.4.0</vertx.version>
<fabric8-vertx-maven-plugin.version>1.0.5</fabric8-vertx-maven-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-dependencies</artifactId>
<version>${vertx.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-mysql-postgresql-client</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>vertx-maven-plugin</artifactId>
<version>${fabric8-vertx-maven-plugin.version}</version>
<configuration>
<redeploy>true</redeploy>
</configuration>
</plugin>
</plugins>
</build>
below is my resource folder structure
the file which is missing is the config.json. It contains values that are used by my class. However when i run the jar file I get the error
java.nio.file.NoSuchFileException
This is how load the file
public static JsonObject config() {
try {
if (jsonObj != null)
return jsonObj;
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
String jsonStr = new String(Files.readAllBytes(Paths.get(classloader.getResource("config.json").getPath())));
return new JsonObject(jsonStr);
} catch (IOException e) {
e.printStackTrace();
return new JsonObject();
}
}
