I'm trying to create a jar file from my project where I use java.utils.logging and I'm getting NoSuchFileException when running the jar with "java -jar .\RideShare-2.0-jar-with-dependencies.jar".
The \logs folder does exist and the code is running perfectly when I run it without a jar file.
What did I do wrong?
error
java.nio.file.NoSuchFileException: data\logs\log.0.lck
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
at java.base/sun.nio.fs.WindowsFileSystemProvider.newFileChannel(WindowsFileSystemProvider.java:121)
at java.base/java.nio.channels.FileChannel.open(FileChannel.java:298)
at java.base/java.nio.channels.FileChannel.open(FileChannel.java:357)
at java.logging/java.util.logging.FileHandler.openFiles(FileHandler.java:512)
at java.logging/java.util.logging.FileHandler.<init>(FileHandler.java:378)
at utils.logs.LogHandler.<clinit>(LogHandler.java:42)
at app.Main.init(Main.java:108)
at app.Main.main(Main.java:69)
Logger file
public class LogHandler{
public static Logger LOGGER = Logger.getLogger(LogHandler.class.getName());
public static ConsoleHandler CONSOLE_HANDLER = new ConsoleHandler();;
public static Handler FILE_HANDLER;
static{
LOGGER.setUseParentHandlers(false);
LOGGER.setLevel(Level.ALL);
try {
//file handler
FILE_HANDLER = new FileHandler("data/logs/log", 20000, 10);
FILE_HANDLER.setFormatter(new LineFormat());
FILE_HANDLER.setLevel(Level.ALL);
//console handler
CONSOLE_HANDLER.setFormatter(new colorFormat());
CONSOLE_HANDLER.setLevel(Level.ALL);
//add custom handlers
LOGGER.addHandler(FILE_HANDLER);
LOGGER.addHandler(CONSOLE_HANDLER);
} catch (SecurityException | IOException e) {
e.printStackTrace();
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.finalProject</groupId>
<artifactId>RideShare</artifactId>
<version>2.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>app.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
.
.
.
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>