[英]Java jdbc classpath on linux server
I have a problem with the jdbc
classpath
in Java. 我在Java中的
jdbc
classpath
有问题。 I am using Maven, but jdbc
is not handable within maven, so I created a "lib" folder with the mysql-connector
.jar und added this jar to the build path of the project. 我正在使用Maven,但是
jdbc
在maven中不方便使用,因此我使用mysql-connector
.jar创建了一个“ lib”文件夹,并将此jar添加到了项目的构建路径中。
If I run it local in eclipse it is all working fine, but when I put the project on my server and try to run it via command line it prints out this error: 如果我在eclipse中本地运行它,一切正常,但是当我将项目放在服务器上并尝试通过命令行运行时,它会打印出此错误:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/eventlist
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at WriteData.writeEventDataToDatabase(WriteData.java:24)
at Main.main(Main.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)
I am using Java 1.8.0_60 and Maven 3.0.5 on CentOS 6. I hope you can tell me how the add the jdbc file to the classpath. 我在CentOS 6上使用Java 1.8.0_60和Maven 3.0.5。希望您能告诉我如何将jdbc文件添加到类路径中。
thanks! 谢谢!
Driver should be in server too. 驱动程序也应该在服务器中。 For example, if you are using tomcat on your server then driver must be in lib folder of tomcat.
例如,如果您在服务器上使用tomcat,则驱动程序必须位于tomcat的lib文件夹中。
You need to do two things: 您需要做两件事:
Here's an example of the mvn:install command: 这是mvn:install命令的示例:
call mvn install:install-file -Dfile=sqljdbc.jar -DgroupId=microsoft -DartifactId=sqljdbc -Dversion=4 -Dpackaging=jar
Here's the pom.xml entry that calls for it in my project: 这是在我的项目中需要它的pom.xml条目:
<dependency>
<groupId>microsoft</groupId>
<artifactId>sqljdbc</artifactId>
<version>4</version>
</dependency>
You'll do the same thing for every JAR your project needs that is not available in a public repository. 您需要为项目所需的每个JAR做同样的事情,而公共存储库中没有。
If I execute mvn:install on my local machine, I see the JAR installed in my local .m2 repository. 如果我在本地计算机上执行mvn:install,我会在本地.m2存储库中看到安装的JAR。 I don't have access to a private, shared repository.
我无权访问私有共享存储库。 If I want my local machine and an integrated build facility to both have access to that JAR I'll have to get it into a private, shared repository that both can see.
如果我想让我的本地计算机和集成的构建工具都可以访问该JAR,则必须将其放入一个私人的共享存储库中,两者都可以看到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.