p***t 发帖数: 698 | 1 这个问题实际上是这样的:
NT下有系统环境变量和用户环境变量。即System Enviroment variable, User
Enviroment variable。在JAVA编程中用到的classpath实际上是User
Classpath。(?)
请问system的classpath用做甚?该如何理解这个classpath?实际编程中,某些
用JAVA编写的应用程序中好象系统的classpath也用到了。例如某些时候就因为
系统classpath没有设置而导致NoClassFoundError的例外。
请指教这两者的区别。 |
|
g****y 发帖数: 323 | 2 Java Tip 105: Mastering the classpath with JWhich
Identify which class will be loaded in your classpath
Summary
The Java classpath has always been a source of frustration
and confusion, despite its seemingly simple concepts. This
article demonstrates a simple tool for unambiguously
identifying which Java class in your classpath the class
loader will load. (1,000 words)
By Mike Clark
Java Tips
one time or another, developers experience frustration when
dealing with the Java classpath. It's not |
|
s*********r 发帖数: 22 | 3 unix下jre的classpath该怎么设?
我用的unix下的/usr/j2se/jre/bin/java,用下面的方法设置CLASSPATH
CLASSPATH=${CLASSPATH}:a.jar:b.jar:c.jar export CLASSPATH
但运行/usr/j2se/jre/bin/java的时候还是找不到a.jar,b.jar,c.jar。
如果我把a.jar,b.jar,c.jar拷贝到/usr/j2se/jre/lib/ext下面就行。但这样好象不是最
好的方法。
有没人遇到过类似情况,怎么解决的? |
|
k****n 发帖数: 369 | 4
but
starting
c肯定是对的,我怎么不记得classpath找jar的时候支持通配符了?
我很久以前写过一个脚本把某个目录下的所有jar加到classpath里面一直用到现在
新的java不需要这么干了?
用-classpath的话是会取代默认CLASSPATH的,所以其他都不用看了 |
|
s***m 发帖数: 28 | 5 Under Unix, you can check your classpath with this command,
echo $CLASSPATH
To add class path, insert new classpath mentioned by fryingfish in your
.bash_profile.
Then you have to reload profile by typing "source $HOME/.bash_profile"
If you have root access, you can add one file under /etc/profile.d/ directory.
This file will contain your export CLASSPATH command. To reload it, just type
. /etc/profile using root. Everything under /etc/profile.d/ will be loaded
everytime the system is started.
|
|
m**c 发帖数: 90 | 6
I don't not quite understand with the translated terminology (in Chinese) as
you mentioned above :-) Let's use an example: you have "my.jar", if you
include "my.jar" in CLASSPATH, every classes (compiled bytecode) in "my.jar"
will be loaded to JVM:
set CLASSPATH=\my.jar (Windows)
export CLASSPATH=/my.jar (Unix)
Since "src.zip" only contains the source code (*.java) not compiled bytecode
(*.classes). Therefore, you cannot add "src.zip" to CLASSPATH (in fact, you
could do it, but J |
|
s********e 发帖数: 340 | 7 能否详细解释一下为什么是c?
/test/games/ 中的games目录是哪里来的?
此外:
java -classpath /test:/home/bob/downloads/*.jar
test:/中的冒号是什么意思?是题目中的笔误?
我对这个-classpath的理解是可以到/test/home/bob/downloads/
的所有jar包中去寻找需要的类。但是答案c是
/test/games/Chess.class
我不明白这个/test/games/目录是怎么来的,和classpath定义的不一样啊?
谢谢! |
|
m******t 发帖数: 2416 | 8 I have seen too many people, including myself, falling for
classpath issues while developing in Java. So here's something
from my experience to help newbies out:
1. Always try to find a Win2K/XP or Linux for your development
work. The DOS prompt of Win98 is simply insufficient for serious
Java development.
2. Grow yourself some good habit. Before just shoveling a jar
onto a classpath, always ask yourself, "does it belong here?"
I have seen a lot of developers hacking their classpath just
for |
|
xt 发帖数: 17532 | 9
Agree. It Win98 sucks. I use NT though. :)
I add one thing: make sure you have only *one* copy of everything
in your classpath. You don't want to end up with multiple copies
which could give you headache on the LinkageError or version conflicts.
In DOS mode, use setlocal ... endlocal to make sure that your classpath
settings are strictly local. Also you could use -classpath option |
|
m******t 发帖数: 2416 | 10
Actually not. One thing not so good about IDE is that it does
too many things for you, one of them being forming the classpath
for you automatically. For example, NetBeans (at least as of 3.3)
forms both compile and run-time classpaths from all the filesystems
you mount, regardless if it's src, or lib, or whatever other folder
you just mounted for convenience. On top of that, it has its own
running classpath included automatically, too.
Fortunately, new generations of IDE's have been adding |
|
m**c 发帖数: 90 | 11
Remember, sometimes, not only class file needs to be in the CLASSPATH, but
also other type of files. For example, properties file. If you take a look
at /jre/lib, you will see some files with extension ".properties". Those
files are used as configuration files which must be in the CLASSPATH,
otherwise, some classes will complain about it. When a directory is included
in the CLASSPATH, you can load any file using
"obj.getClass().getResourcesAsStream(...)". This can be very useful: let |
|
j******3 发帖数: 299 | 12 jnsong@ubuntu:~/lib$ echo $CLASSPATH
/home/jnsong/Downloads/htmlunit-2.11/lib/*.jar
In /etc/environment, I have
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/
games"
export CLASSPATH="/home/jnsong/lib/*.jar"
in my .bashrc, I have
export CLASSPATH="/home/jnsong/Downloads/htmlunit-2.11/lib/*.jar"
in that lib folder, I have:
jnsong@ubuntu:~/Downloads/htmlunit-2.11/lib$ ls
commons-codec-1.7.jar jetty-http-8.1.7.v20120910.jar
commons-collections-3.2.1.jar jetty-io-... 阅读全帖 |
|
L******r 发帖数: 199 | 13 【 以下文字转载自 Linux 讨论区 】
发信人: LordBear (LordBear), 信区: Linux
标 题: Classpath setting question
发信站: BBS 未名空间站 (Mon Jun 25 22:30:29 2007), 转信
一脚本,同一RH服务器,老板连过去没问题,我就跑不了:
老板说Check your CLASSPATH and location of java - should be
/aa/app/jdk1.6.0_01/bin/java
$ echo $SHELL
/bin/tcsh
我的默认Shell是tcsh,我在/etc目录下修改了.bashrc,但是一点用处没有。
set JAVA_HOME=/aa/app/jdk1.6.0_01/bin/java
export JAVA_HOME
set PATH=$JAVA_HOME/bin:$PATH
export PATH
set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export CLASSPAT |
|
s********e 发帖数: 340 | 14 A UNIX user named Bob wants to replace his chess program with a new one, but
he is not sure where the old
one is installed. Bob is currently able to run a Java chess program starting
from his home directory /home/bob
using the command:
java -classpath /test:/home/bob/downloads/*.jar games.Chess
Bob's CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar What is a
possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
... 阅读全帖 |
|
u*******d 发帖数: 289 | 15 【 以下文字转载自 Unix 讨论区 】
【 原文由 unlimited 所发表 】
as title
I want to setup the oracle db class path so my java prog can use.
Am I supposed to do
#!bin/sh
CLASSPATH=".:RACLE_HOME/jdbc/..."
export CLASSPATH
java
but where I put it? |
|
g**y 发帖数: 4 | 16 I am using tcsh SHELL
I use following commnad to set CLASSPATH
set CLASSPATH = ( /homes/yd02/yd/spring/cw/distributed_system/DSCW-Linux)
Is it a correct way?
PS: DSCW-Linux contains the package directories. |
|
g****o 发帖数: 1284 | 17 Thinking in Java的第5章讲了如何创建自己的package,里面提到了一个CLASSPATH环境
变量。书里给了一个例子:
//:List.java
// Creating a package
package com.bruceekel.util;
public class List {
public List() {
System.out.println("com.bruceeckel.util.List");
}
}
然后作者说把生成的类文件放在他自己系统的一个子目录下:
C:\DOC\JavaT\com\bruceeckel\util
在他的机器上,CLASSPATH = .; D:\JAVA\LIB; C:\DOC\JavaT
请问在UNIX下有什么命令可以查看并修改这个路径? |
|
f********h 发帖数: 149 | 18 if you use bash, export CLASSPATH=your_class_path_separated_by_colon
or csh, setenv CLASSPATH your_class_path_separated_by_colon |
|
m**c 发帖数: 90 | 19
Wrong. Java archive files can be in either JAR or ZIP format. For example,
Oracle JDBC (thin) driver is packaged as "classes12.zip". You can tread just
ZIP file as JAR file:
(Windows) set CLASSPATH=...\classes12.zip;...
(UNIX) export CLASSPATH=.../classes12.zip:... |
|
e***g 发帖数: 158 | 20
never heard of. jre/lib as classpath is for resources like font.properties,
images/...gif. rt.jar is in bootclasspath and not affected by classpath |
|
w***y 发帖数: 6251 | 21 我有一个hmm的java code,做成一个jar文件,想在另外一个java file里用,已经把那个
jar文件放在classpath里了,但是定义HMM hmm的时候,还是说can't resolve symbol
但是很奇怪,我一开始做的一个testhmm就是把这个jar文件放在classpath上,是能用的,
不知道为啥放到另外一个java文件里又不行了
哪位高人指点一下吧//bow |
|
j******3 发帖数: 299 | 22 用的ubuntu12.04 64bit
我把htmlunit那个lib文件都拷贝到lib的目录下,设置了classpath,但是每次complie
都出错。
求助各位,折腾了好久不知道什么问题
Debugging information as follows:
jnsong@ubuntu:~$ echo $CLASSPATH
/home/jnsong:/home/jnsong/Downloads/htmlunit-2.10/lib
_____________________________________________
jnsong@ubuntu:~$ javac myClient.java
myClient.java:6: error: package com.gargoylesoftware.htmlunit does not exist
import com.gargoylesoftware.htmlunit.Page;
^
myClient.java:7: error: package com.gargo... 阅读全帖 |
|
j******3 发帖数: 299 | 23 谢谢你的回复。请问那个路径是在哪里设置
我尝试用
vim .bashrc
加入了一行
export CLASSPATH="/jar locations/*.jar"
然后source .bashrc
同时用
sudo vim /etc/environment 里面加入类似的
CLASSPATH="/jar locations/*.jar"
Reboot
还是提示同样的错误。。。。 |
|
g*****i 发帖数: 2162 | 24 感觉这里的冒号对应windows里的分号,从CLASSPATH可以看出. |
|
s***8 发帖数: 1136 | 25 A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)
CLASSPATH env is ignored since -cp is explicitly used.
A, B can be eliminated since they don't contain package.
The command doesn't specify -jar option so manifest.mf is irrelevant
If there is no C, then G is the next possib... 阅读全帖 |
|
z****u 发帖数: 15 | 26
Starting from Java 2 the default classpath is stored in
registry. Usually the only thing recorded is the path where
JDK and JRE is installed. Then JVM is going to figure out
the classes under certain subdirectories.
For example the key (win98)
MyComputer\HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime
Environmenet\1.2 stores JavaHome as C:\Program
Files\JavaSoft\JRE\
then Java runtime is going to locate all system classes in
C:\Program Files\JavaSoft\JRE\1.2\lib\rt.jar
Also Java 2 supports st |
|
t*****x 发帖数: 3 | 27 我已经试过在control panel->system->environment variables中
加入CLASSPATH这个变量,但是不奏效。
请高手指点,谢谢 |
|
s*******s 发帖数: 3 | 28 better use java -classpath ... |
|
z****g 发帖数: 2497 | 29 1. no. no jar file will be included.
2. I don't think java classpath would recognize zip file at all. |
|
a***n 发帖数: 1616 | 30 我的关键问题是,如果是.jar,可不可以只写目录名,它会自动找目录里所有jar
里面包含的class?
为什么我装的J2SDK,默认的classpath是 jdk/lib/tools.jar:jdk/jre/lib
其中jdk/jre/lib里有java所需的所有class包:rt.jar。
它为什么不用jdk/jre/lib/rt.jar,或者干脆用 jdk/share/src.zip呢(src.zip也包含
java所需的所有class)。
是不是jdk1.4放宽要求,对jar内建支持,不用些全jar的文件名,只要目录它就可以搜? |
|
a***n 发帖数: 1616 | 31 多谢,完全明白了.
那么安装的j2sdk,它默认设classpath=.:/lib/tools.jar:/jre/lib
里的"/jre/lib"根本没有意义嘛,除非你想把一个个的class文件放那里,谁干?
目录它=目录,它:) |
|
j*******r 发帖数: 9 | 32 for more complex applications that include many classes/jars in the CLASSPATH,
how to better off crafting a makefile/startup script/batch file per
application so to cut down on alot of typing)... |
|
n*****k 发帖数: 123 | 33
CLASSPATH,
Check out Ant if you need to compile the source files and make a package, if
just want to run, maybe a few lines of shell script will do. |
|
c*****t 发帖数: 562 | 34 I have a class which extends an abstract class, they are in the same
directory. The abstract class compiled fine, but I have to add the current
directory to the classpath or the extended class won't be able to find the
abstract class.
Is this normal? I thought java should be able to find and use anything in the
same directory. Or is it because it extends another class? |
|
A**o 发帖数: 1550 | 35 Q1, dependency analysis
Q2, write another program to generate the jar list for classpath
or use the ide to run it, and copy/paste how ide start the jvm...
a
the
database,
directory.
of |
|
z***h 发帖数: 405 | 36 classpath can be built into your jar file |
|
T*****e 发帖数: 361 | 37 Thanks a lot for your help. I will include the classpath in my jar file for
now and deal with dependency issue at a later time. |
|
l*********s 发帖数: 5409 | 38 I am trying to compile demo of jasperreport, funny thing is that, if I put
the appache common logging/beanutil jars in the %JAVA%\lib\ext, compiling is
OK.
But if the libraries locate in somewhere else, and referenced through %
classpath%, ant complains. Why is such a different behavior? |
|
r*****l 发帖数: 2859 | 39 Java load class的顺序是:
1,bootstrap classloader,load最基本的runtime classes。bootstrap classloader
在Java世界里基本是神一样的class,有着不受Java规则制约的行为。
2,extension classloader,它load你放在java\lib\ext里面的jar。一般这个目录里
面放一些OS dependent的东西,等等。
3,system classloader,应该是AppClassLoader,load classpath里面的,WEB-INF\
lib里面的classes。
jasperreport的东西尽量用system loader来load。ant complaint应该是没设置好的缘
故。
is |
|
T****U 发帖数: 3344 | 40 your are using jar files, rite?
add this to your classpath
/home/jnsong/Downloads/htmlunit-2.10/lib/*.jar
complie
exist |
|
T****U 发帖数: 3344 | 41 show me your current classpath |
|
r****z 发帖数: 18 | 42 如果我将jar文件放在classpath,那java自己的类都找不到了,结果main都执行不了,
这怎么办?Java本身的类都放在哪里?试着将orace提供的jdbc类复制到Java\jdk1.6.0
_05\bin或\lib下面好像没用。:(
多谢! |
|
g*****g 发帖数: 34805 | 43 java -classpath odbc.jar;other jars;directory (. for current) YourMain
.0 |
|
f**y 发帖数: 138 | 44 set CLASSPATH=.;c:\path\to\your\jdbc.jar |
|
g******a 发帖数: 730 | 45 Linux/Unix下如何改变CLASSPATH啊?
这个再什么文件里?
//bow |
|
f********h 发帖数: 149 | 46 depends the shell you use.
If you use bash, put the following in .bashrc
export CLASSPATH=what_ever_you_want |
|
r*****s 发帖数: 985 | 47 csh/tcsh:
setenv CLSSPATH yourpath
不过开发的时候最好不要在自己的环境里设CLASSPATH,很容易
后来就忘记加了,结果别人用起来classnotfound。。。 |
|
x*********g 发帖数: 11508 | 48 nod nod
如果是一个JAR文件需要用到CLASSPATH, 可以在manifest文件里设置Class-Path, 这样
就一直在你的JAR里,不会忘记(或:不需要记起〕。 |
|
y**o 发帖数: 4 | 49
Have set the env var:
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${ORACLE_HOME}/lib
setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/sqlj/lib/translator.zip
setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/sqlj/lib/runtime.zip
setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/sqlj/lib/runtime12.zip
setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/sqlj/lib/runtime12ee.zip
setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/sqlj/lib/classes12.zip
setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/sqlj/lib/runtime12.jar
而且那个run |
|
q*c 发帖数: 9453 | 50 刚刚开始用java , 如果这问题非常蠢,高手们不要见怪。
我编译了一个简单的hello world 程序。怎莫也不能运行,
总是出现下面的错误:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
花了一天的时间,终于发现了问题, classpath.
如果我清楚了 classpath 的设置,set classpath= , 就好了。
但是无论我设置了什莫 non empty classpath, 就不能运行。
问题
1。 classpath 是 compile 的时候才起作用吧?
2。 我把jre/lib 下面所有的jar 全部设置在classpath 里面的,可是无论我社自身末,
只要有classpath, 就是不行。这不能理解吧?
多谢诸位指教! |
|