英文:
How to add a .jar file to webserver's lib directory?
问题
我在执行需要com.mysql.jdbc.Driver的代码时遇到问题。尽管在项目结构中有mysql-connector-java-5.1.25-bin.jar(我正在运行基于Gradle的Spring Boot应用程序,并尝试将其连接到本地托管的XAMMP上的MySQL数据库),但当我执行代码时,我收到ClassNotFoundException。我在这里阅读了一些类似的帖子,人们说mysql-connector-java-5.1.25-bin.jar还应该添加到web服务器的lib目录中。我不知道在哪里找到它,或者如何做,因为我对Java和处理.jar文件还不太熟悉。
英文:
I am having an issue when executing code which requires the com.mysql.jdbc.Driver. Although I have the mysql-connector-java-5.1.25-bin.jar in my Project Structure (I am running a Gradle-based, Spring Boot application and I am trying to connect it to a locally hosted MySQL database on XAMMP) when I execute the code I am getting a ClassNotFoundException. I have read up on some similar threads here and people say that the mysql-connector-java-5.1.25-bin.jar should also be added to the webserver's lib directory. I have no clue where to find it, or how to do it at all because I am kinda new to java and handling .jar files.
答案1
得分: 2
如果您使用的是 SpringBoot 应用程序和 Maven,则需要在您的 pom.xml 文件中添加以下依赖:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
或者如果您使用的是 Gradle,则需要在您的 build.gradle 文件中添加以下依赖:
compile "mysql:mysql-connector-java:5.1.49"
英文:
If you are using a SpringBoot application and maven, you need to add to your pom.xml this dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
Or if you use the gradle, you need to add the dependency to your build.gradle file:
compile "mysql:mysql-connector-java:5.1.49"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论