java中的类路径到底是什么? [英] What exactly is a class path in java?

查看:571
本文介绍了java中的类路径到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个可以在笔记本电脑上完美运行的程序,但是我真的希望它能在我拥有的服务器上运行。 使用NetBeans ,我已经清理并构建了项目。我在服务器上复制了文件夹dist的内容,但似乎无法通过使用命令

I wrote a program that works on my laptop perfectly, but I really want it to work on a server that I have. Using NetBeans, I've clean and built the project. I copied the contents of the folder dist on my server but I cannot seem to get to work by using command


java -jar nameOfFile.jar来工作

java -jar nameOfFile.jar

我收到错误

java.lang.NoClassDefFoundError: org/....

我一直在做一些阅读,我所收集的是,我需要非常指定我所使用的库的位置。好吧,它们位于一个名为lib的子文件夹中。

I have been doing some reading and from what I gather is that I need to pretty much specify where the libraries that I've used are located. Well they are located in a subfolder called lib.

问题:

那么我要做些什么才能成为能够运行我的jar吗?

So what would I need to do in order to be able to run my jar?

推荐答案

CLASSPATH是一个环境变量,可帮助我们从其开始的地方学习Java虚拟机。

CLASSPATH is an environment variable that helps us to educate the Java Virtual Machine from where it will start searching for .class files.

我们应该将包层次结构的根存储在CLASSPATH环境变量中。

We should store the root of the package hierarchies in the CLASSPATH environment variables.

在我们的项目中添加或使用jar库的情况下,应将jar文件的位置放在CLASSPATH环境变量中。

In case of adding or using jar libraries in our project, we should put the location of the jar file in the CLASSPATH environment variable.

示例:如果我们在java项目中使用jdbc mysql jar文件,则必须在CLASSPATH环境变量中更新mysql jar文件的位置。如果我们的mysql.jar在c:\driver\mysql.jar中,则

Example: If we are using jdbc mysql jar file in our java project, We have to update the location of the mysql jar file in the CLASSPATH environment variable. if our mysql.jar is in c:\driver\mysql.jar then

我们可以在Windows中通过DOS设置类路径

We can set the classpath through DOS in Windows

set CLASSPATH=%CLASSPATH%;c:\driver\mysql.jar 

在Linux中,我们可以这样做

In Linux we can do

export CLASSPATH=$CLASSPATH:[path of the jar]

希望有帮助!

这篇关于java中的类路径到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆