Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-base -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>15.0.1</version>
<version>11.0.2</version>
</dependency>


Expand Down Expand Up @@ -80,10 +80,23 @@
<artifactId>log4j-api</artifactId>
<version>2.13.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -93,6 +106,23 @@
<target>15</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Main-Class>
by.javafx.petrovich.demo.EmployeeApplication
</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
Expand All @@ -102,7 +132,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>by.javafx.petrovich.demo/by.javafx.petrovich.demo.EmployeeApplication</mainClass>
<mainClass>by.javafx.petrovich.demo.EmployeeApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Optional;

import static by.javafx.petrovich.demo.controller.AlertMessages.CANT_LOAD_FILE;
import static by.javafx.petrovich.demo.controller.AlertMessages.CANT_LOAD_XML_FILE;
Expand All @@ -35,9 +37,9 @@ public class EmployeeApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(EmployeeApplication.class.getResource("employeeSort.fxml"));
Path path = Paths.get("src/main/resources/icons/bussiness-man.png");
try {
InputStream inputStream = new FileInputStream(path.toFile());
InputStream inputStream = Optional.ofNullable(EmployeeApplication.class.getResourceAsStream("/icons/bussiness-man.png"))
.orElseThrow(FileNotFoundException::new);
Image image = new Image(inputStream);
Scene scene = new Scene(fxmlLoader.load(), 600, 400);
stage.setScene(scene);
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/by/javafx/petrovich/demo/util/PropertyLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package by.javafx.petrovich.demo.util;

import by.javafx.petrovich.demo.EmployeeApplication;
import javafx.scene.control.Alert;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
Expand All @@ -11,6 +12,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.Properties;

import static by.javafx.petrovich.demo.controller.AlertMessages.FAILED_READING_PROPERTIES_FILE;
Expand All @@ -22,17 +24,17 @@
*/
public class PropertyLoader {
private static final Logger LOGGER = LogManager.getLogger();
private static final String PROPERTY_PATH = "src/main/resources/properties/jdbc-sql-config.properties";
private static final String PROPERTY_PATH = "/properties/jdbc-sql-config.properties";
private static final Properties PROPERTIES = new Properties();
private static final HealtheCheckController healtheCheckController = new HealtheCheckController();

static {
Path path = Paths.get(PROPERTY_PATH);
try {
InputStream inputStream = new FileInputStream(path.toFile());
InputStream inputStream = Optional.ofNullable(EmployeeApplication.class.getResourceAsStream(PROPERTY_PATH))
.orElseThrow(FileNotFoundException::new);
readProperties(inputStream);
} catch (FileNotFoundException e) {
LOGGER.log(Level.ERROR, "File does not exist, initialization failed.", PROPERTY_PATH);
} catch (Exception e) {
LOGGER.log(Level.ERROR, "File {} does not exist, initialization failed.", PROPERTY_PATH);
healtheCheckController.showAlert(NO_PROPERTIES_FILE, Alert.AlertType.ERROR, ERROR);
throw new RuntimeException("File does not exist, initialization failed.", e);
}
Expand All @@ -48,7 +50,7 @@ private static void readProperties(InputStream inputStream) {
PROPERTIES.load(inputStream);
LOGGER.log(Level.INFO, "Reading properties file successfully.");
} catch (IOException e) {
LOGGER.log(Level.ERROR, "Reading properties file failed", e.getMessage());
LOGGER.log(Level.ERROR, "Reading {} properties file failed", e.getMessage());
healtheCheckController.showAlert(FAILED_READING_PROPERTIES_FILE, Alert.AlertType.ERROR, ERROR);
throw new RuntimeException("Reading properties file failed.", e);
}
Expand Down