diff --git a/pom.xml b/pom.xml index da93d59..a4b4619 100644 --- a/pom.xml +++ b/pom.xml @@ -18,18 +18,18 @@ org.openjfx javafx-controls - 15.0.1 + 11.0.2 org.openjfx javafx-fxml - 15.0.1 + 11.0.2 org.openjfx javafx-base - 15.0.1 + 11.0.2 @@ -80,10 +80,23 @@ log4j-api 2.13.0 + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.4.0 + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.4.0 + org.apache.maven.plugins maven-compiler-plugin @@ -93,6 +106,23 @@ 15 + + org.apache.maven.plugins + maven-jar-plugin + + + + true + lib/ + + + + by.javafx.petrovich.demo.EmployeeApplication + + + + + org.openjfx javafx-maven-plugin @@ -102,7 +132,7 @@ default-cli - by.javafx.petrovich.demo/by.javafx.petrovich.demo.EmployeeApplication + by.javafx.petrovich.demo.EmployeeApplication app app app diff --git a/src/main/java/by/javafx/petrovich/demo/EmployeeApplication.java b/src/main/java/by/javafx/petrovich/demo/EmployeeApplication.java index cc8afdc..d257496 100644 --- a/src/main/java/by/javafx/petrovich/demo/EmployeeApplication.java +++ b/src/main/java/by/javafx/petrovich/demo/EmployeeApplication.java @@ -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; @@ -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); diff --git a/src/main/java/by/javafx/petrovich/demo/util/PropertyLoader.java b/src/main/java/by/javafx/petrovich/demo/util/PropertyLoader.java index 5b1f4a8..5d41308 100644 --- a/src/main/java/by/javafx/petrovich/demo/util/PropertyLoader.java +++ b/src/main/java/by/javafx/petrovich/demo/util/PropertyLoader.java @@ -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; @@ -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; @@ -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); } @@ -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); } diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF similarity index 100% rename from src/main/java/META-INF/MANIFEST.MF rename to src/main/resources/META-INF/MANIFEST.MF