当我运行该程序时,我得到以下错误:
谢谢!
public class Application {
public static void main(String[] args) throws ClassNotFoundException{
System.out.println("Application class created\n");
Connection connection = null;
try {
Class.forName("org.sqlite.JDBC");
}catch (ClassNotFoundException e){
System.err.println("Class not found"+e);
}
try{
connection = DriverManager.getConnection("jdbc:sqlite::memory:");
Statement statement = connection.createStatement();
statement.setQueryTimeout(33);
statement.executeUpdate("create table demo (id integer, name string)");
statement.executeUpdate("insert into demo(1, 'A')");
ResultSet mySet = statement.executeQuery("select * from demo");
while(mySet.next()){
System.out.println("Name is : "+mySet.getString("name"));
System.out.println("Id is : "+mySet.getInt("id"));
}
}
catch (SQLException sqlException){
System.err.println(sqlException.getMessage());
}
finally {
try{
if(connection!=null)
connection.close();
}
catch (SQLException sqlException){
System.err.println(sqlException);
}
}
}
}
我的文件依赖关系是:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>path-to-mainclass-Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
发布于 2018-10-05 05:22:03
删除maven-jar-plugin
并使用此插件生成包含所有依赖项的jar,并运行具有依赖项的jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
your.main.Class
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
https://stackoverflow.com/questions/52654954
复制相似问题