1

I have a javaFX application and I want the user to be able to run it without a development environment, that is, just click on the jar file and work with the graphical application

public class RunFrame extends Application {

    static Logger LOGGER;
    static {
        try(FileInputStream ins = new FileInputStream("src/main/resources/log.config")) {
            LogManager.getLogManager().readConfiguration(ins);
            LOGGER = Logger.getLogger(RunFrame.class.getName());
        } catch (IOException e) {
            LOGGER.log(Level.WARNING,"Error ", e);
        }
    }
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage)  {
        try {
            FXMLLoader loader = new FXMLLoader();
            URL xmlUrl = getClass().getResource("/RunFrameScene.fxml");
            loader.setLocation(xmlUrl);
            Parent root = loader.load();
            stage.setTitle("App");
            stage.getIcons().add(new Image(RunFrame .class.getClassLoader().getResourceAsStream("logo.png")));
            stage.setScene(new Scene(root));
            stage.show();
            LOGGER.log(Level.INFO,"Success ");
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE,"Error", e);
        }
    }
}

The class through which the application is launched

public class FrameRunApp {
    static Logger LOGGER;
    static {
        try(FileInputStream ins = new FileInputStream("src/main/resources/log.config")){
            LogManager.getLogManager().readConfiguration(ins);
            LOGGER = Logger.getLogger(FrameRunApp .class.getName());
        }catch (Exception e){
            LOGGER.log(Level.WARNING,"Error ", e);
        }
    }

    public static void main(String[] args) {
            FrameRunApp.main(args);
        }
    }

Also I have a pom.xml file

<?xml version='1.0'?>

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.activemq.examples.broker</groupId>
        <artifactId>jms-examples</artifactId>
        <version>2.27.1</version>
    </parent>

    <artifactId>jmx</artifactId>
    <packaging>jar</packaging>
    <name>FrameApplication</name>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-nop</artifactId>
            <version>1.7.36</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>19</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>
    </dependencies>
</project>

I don't really understand how to create a jar file and just run the app's application on it, rather than by designing run the app's launcher method.

Vanish
  • 57
  • 6
  • 3
    I'd probably give [this](https://github.com/Akman/jpackage-maven-plugin) a try. That's not the way to read a custom log config - you'd need `getResourceAsStream` when it's any sort of packaged. Why do you need that anyway btw? – g00se Jun 21 '23 at 11:25
  • i get fxml file config like this. I need to make a jar file from the application so that a user without a development environment can use a graphical application – DarkSoul Jun 21 '23 at 13:03
  • As noted by g00se and by comments on your previous question, do not use `FileInputStream` to read resources. What you're doing will only work in your development environment and will break once packaged in a JAR file or JRT image. Use `Class#getResource(String)` and/or `Class#getResourceAsStream(String)`. – Slaw Jun 22 '23 at 04:29
  • Actually the pom.xml mentions SpringBoot, so if you want to configure logging, you should follow the SpringBoot logging documentation (which won’t tell you to do what you are currently doing or to write code yourself to load logging configuration from a resource). – jewelsea Jun 22 '23 at 05:26
  • SpringBoot maven plugin can create a single jar for an application, again study the SpringBoot documentation for this. However, it might not be what you want, as the generated jar is not Java module system aware, so you would need not to have JavaFX modules as maven dependencies and to develop, package and run the app using a JDK or JRE that includes JavaFX modules, such as Azul Zulu JDK FX distributions. – jewelsea Jun 22 '23 at 05:32
  • Maybe you want [maven shade](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing) instead, or the jpackage solution mentioned by g00se or something from [packaging in the JavaFX tag](https://stackoverflow.com/tags/javafx/info). – jewelsea Jun 22 '23 at 05:37

1 Answers1

-3

Creating Executable Jars

https://taylorial.com/tools/jar/

Check out the link above, as it mentions clearly and step by step how to create an executable .jar file

Elle Bishop
  • 307
  • 11
  • Include the relevant info from the link in the answer. Links rot – Jeff Bennett Jun 24 '23 at 19:57
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 24 '23 at 19:57