简体   繁体   English

java数据库和jar文件

[英]java DB and jar file

we have a standalone project.我们有一个独立的项目。 we are using Java DB and we are writting our code on netbeans.我们正在使用 Java DB,我们正在 netbeans 上编写我们的代码。 we can conncet to DB with using IDE and we can do what we want but when we make it jar file it couldnt connect to database .我们可以使用 IDE 连接到数据库,我们可以做我们想做的事情,但是当我们把它做成 jar 文件时,它无法连接到数据库。 how can we solve this problem thanks我们如何解决这个问题谢谢

The database driver has to be in classpath when you run your application as JAR.当您将应用程序作为 JAR 运行时,数据库驱动程序必须在类路径中。 When you start the application in eclipse the driver is found in the build path.当您在 eclipse 中启动应用程序时,驱动程序会在构建路径中找到。 That's why your application works here.这就是您的应用程序在这里工作的原因。

Another solution would be to embed the driver's JAR in your JAR file.另一种解决方案是将驱动程序的 JAR 嵌入您的 JAR 文件中。

first check where is your jar located,most probably it is outside the project thats why error occurs.首先检查您的 jar 在哪里,很可能它在项目之外,这就是发生错误的原因。 put them in your project and set path properly in classpath file like :将它们放在您的项目中并在类路径文件中正确设置路径,例如:

<classpathentry exported="true" kind="lib" path="WEB-INF/lib/castor-1.1.2-commons.jar"/>

right now if you see your path is look like :现在,如果您看到您的路径如下所示:

<classpathentry exported="true" kind="lib" path="D:/apache-tomcat-6.0.14/apache-tomcat-6.0.14/lib/servlet-api.jar"/>

which is wrong.这是错误的。

provide your classpath file and error log if still error occurs.如果仍然发生错误,请提供您的类路径文件和错误日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM