1

I made JavaFX application in Intelij Idea. I have database file in resource folder with all the stuff like video and icons. I tried to use Maven to build a project but it was unsuccessfully.

I added dependencies of my libraries that I use in the project to pom file.

I would like to have a folder with all necessary files like video and icons and also database file that can be changed at any time by user.

I would like to have an exe file in that folder just to make easier to run my program in any other windows machine.

I know there is laucnh4j application, but I even can't build jar file with all libraries and database file.

How can I build jar or exe file in Intelij Idea?

Where should the database file be placed?

My project structure:

Project structure 1 Project structure 2

database class

Pom file:

<?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>kentforth</groupId>
<artifactId>CategoryCards</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
</properties>

<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.controlsfx</groupId>
        <artifactId>controlsfx</artifactId>
        <version>9.0.0</version>
    </dependency>

    <dependency>
        <groupId>com.jfoenix</groupId>
        <artifactId>jfoenix</artifactId>
        <version>9.0.6</version>
    </dependency>

    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.23.1</version>
    </dependency>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>

</dependencies>

EDIT:

I've decided not to use Maven for making a build because It is hard for me to understand how to build a jar file or exe file with database. I used standard Intelij Idea's method to make jar, I built a jar file with libraries and database file, I made exe file with laucnh4j app and packed that exe file to installator with Innmo setup

When I launch the application in another computer database works fine and I can write/read database. But the problem is I can't find that database file in OS Windows

I think it is because database fle is packed to jar file.

Is there any solution how to make my application read database file from folder with jar file, not from direct jar?

My friend will use this database file to read/write information to database

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kentforth
  • 489
  • 1
  • 6
  • 19
  • Possible duplicate of [How to include SQLite database in executable Jar?](https://stackoverflow.com/questions/12019974/how-to-include-sqlite-database-in-executable-jar) – Slaw Jan 20 '19 at 10:16
  • Note that the database file will be read-only. – Slaw Jan 20 '19 at 10:16
  • @Slaw why is it so? I can change data in database file through my application – kentforth Jan 20 '19 at 10:19
  • Resources in JAR files are read-only. Or at least, they usually are. – Slaw Jan 20 '19 at 10:19
  • @Slaw Where should I place ddadtabase file that file readable/writebale through my application? – kentforth Jan 20 '19 at 10:23
  • @Slaw your link is not good enough because different platform is used in not through maven – kentforth Jan 20 '19 at 10:23
  • The build tool is not relevant, the important part is the URL used for getting a connection (if you still want to use a database _resource_). As to putting the database somewhere you can read-write, you could try the application directory, a folder in the user home directory, appdata (since you seem to be focused on Windows), or lookup where each platform stores application data and dynamically resolve the database path. – Slaw Jan 20 '19 at 13:19
  • @Slaw I used a String in my class that can see my database file in any place on OS Windows `private static final String SQCONN = "jdbc:sqlite::resource:database.db";` Please, check my edit – kentforth Jan 21 '19 at 06:39

0 Answers0