本文介绍了Mac上的CLASSPATH,以及Mac如何查找mysql-connector-java-bin.jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mac OS X 10.6上是否有默认的类路径?当我echo $CLASSPATH时,什么都不会出现.在我的.profile中,我仅看到设置了PATH变量.我的问题是我的servlet似乎找不到合适的驱动程序来连接到mysql服务器.我将EclipseGlassfish v3MAMP用于MYSQL服务器.

Is there a default classpath on Mac OS X 10.6? When I echo $CLASSPATH, nothing would show up. In my .profile, I only see PATH variable being set. My problem is that My servlet cant seem to find a suitable driver to connect to the mysql server. I use Eclipse, with Glassfish v3 and MAMP for MYSQL server.

推荐答案

有几种方法可以使Java在Mac OS X上看到JAR:

There are several methods of getting JARs to be seen by Java on Mac OS X:

  • 将其放在/Library/Java/Extensions
  • 创建/编辑CLASSPATH环境变量
  • 使用-cp选项明确指定类路径.
  • Place it in /Library/Java/Extensions
  • Create/edit the CLASSPATH environment variable
  • Specify the classpath explicitly with the -cp option.

默认情况下未设置CLASSPATH环境变量,但可以选择设置.但是请注意,您在~/.profile中设置的任何环境变量都只会在您的终端会话中生效,而不会影响任何GUI应用程序.如果要设置环境变量以使其影响GUI应用程序,则可以创建一个名为~/.MacOSX/environment.plist的文件,其中包含您的环境变量.对该文件所做的任何更改将在您下次登录时生效.

The CLASSPATH environment variable is not set by default, however, you can set it if you so choose. Be aware, however, that any environment variables that you set in ~/.profile will only take effect within your Terminal session and will not affect any GUI applications. If you want to set environment variables so that they affect your GUI applications, you can create a file named ~/.MacOSX/environment.plist that includes your environment variables. Any changes made to that file will take effect when you next login.

正如已经观察到的那样,将JAR放在extensions文件夹中或修改CLASSPATH环境变量通常是不好的主意,因为它们可能导致依赖地狱.更好的方法是将JAR与工件捆绑在一起,并适当地设置元数据,以便它们位于工件的类路径中.如果您使用 Apache Maven2 来构建您的工件,则可以使其自动下载并捆绑任何第三方依赖项,并且为您的工件适当地设置类路径.

As has been observed, placing JARs in the extensions folder or modifying the CLASSPATH environment variable are generally bad ideas since they can lead to dependency hell. A better way is to bundle your JARs with your artifact and to set the metadata appropriately so that they are on your artifact's classpath. If you use Apache Maven2 to build your artifact, you can have it automatically download as well as bundle any thirdparty dependencies and set the classpath appropriately for your artifact.

这篇关于Mac上的CLASSPATH,以及Mac如何查找mysql-connector-java-bin.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:55