Good day! I do the project in IDEA with use of SQLite. In the development environment, the project is quite working, but after building on maven a database file is created and this is where it ends. It weighs 0 bytes, when opened via SqliteBrowser does not find any 1 table, respectively.
Here is the pom.xml 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>MoneyManager</groupId> <artifactId>MoneyManager</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifestFile> src/main/java/META-INF/MANIFEST.MF </manifestFile> <manifest> <addClasspath>true</addClasspath> <mainClass>Main</mainClass> <packageName>MoneyManager</packageName> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <includeScope>compile</includeScope> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc --> <dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> <version>3.8.11.2</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.10</version> </dependency> <!-- https://mvnrepository.com/artifact/com.toedter/jcalendar --> <dependency> <groupId>com.toedter</groupId> <artifactId>jcalendar</artifactId> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/com.lowagie/itextpdf --> <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version>4.2.1</version> </dependency> </dependencies> </project> here is the java code:
package util; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * Created by user on 23.08.16. */ public class DbHelper { private Connection connection; private String URL = "jdbc:sqlite:database.db"; private String DRIVER = "org.sqlite.JDBC"; private static DbHelper ourInstance = new DbHelper(); public static DbHelper getInstance() { return ourInstance; } private DbHelper() { try { Class.forName(DRIVER); this.connection = DriverManager.getConnection(URL); createTables(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } public Connection getConnection() { return connection; } private void createTables() { try { Statement st = connection.createStatement(); InputStream is = Files.newInputStream(Paths.get("./src/main/java/createbase/database.sql")); StringBuilder sb = new StringBuilder(); while (is.available() > 0) { char x = (char) is.read(); sb.append(x); if(x == ';') { st.execute(String.valueOf(sb)); sb = new StringBuilder(); } } st.close(); } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
./src/main/java/createbase/database.sqlpath./src/main/java/createbase/database.sql. Do you have this directory / file in the "packaged" version? - Chubatiy PMgetClass().getResourceAsStreaminstead ofFiles.newInputStream. Well, the path parameter (for example, if it's just in resources, without subfolders, then it will be justgetClass().getResourceAsStream("database.sql")- Chubatiy