Topic: classpath的两个问题 ?

  Print this page

1.classpath的两个问题 ? Copy to clipboard
Posted by: snooopy
Posted on: 2005-09-26 18:40

我想导入一个a.jar

如果用在cmd的话,
javac -classpath c:\a.jar myjava.java
javac -cp c:\a.jar myjava.java
但每次编译都要加这样的参数,很麻烦,能否想平时那样在代码里import,直接编译就好了 ?

我找了两个路径:
C:\j2sdk1.4.2_07\src.zip
C:\j2sdk1.4.2_07\jre\lib\rt.jar 这个我用verbose参数得出来的
我将a.jar添加到这两个包里,在代码里import还是找不到a.jar

1:如何让我在写代码时直接import上去,编译直接javac myjava.java就行了不要加那些参数

2:如何让这个包在java下,也就是让我要导入的这个包放到java下,import java.a.*;

2.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: why
Posted on: 2005-09-27 00:07

用batch檔處理classpath便不麻烦
或者用ant

假如真有閣下說的import,才是不靈活

3.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: snooopy
Posted on: 2005-09-27 02:00

什么意思啊 ? 我听不懂呀

4.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: why
Posted on: 2005-09-27 05:23

> 什么意思啊 ? 我听不懂呀
什么听不懂??Question
> SET ClasspathForMyJava=[what you want to put onto the classpath for myjava.java]
> javac -classpath %ClasspathForMyJava% myjava.java

5.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: snooopy
Posted on: 2005-09-28 03:23

这样一来,每次编译都要加那些麻烦的参数晕

6.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: zcjl
Posted on: 2005-09-28 09:10

那就用ant吧,把需要的jar包都放到lib,然后在build.xml中定义一个指向这个lib文件夹下所有jar包的fileset作为classpath属性,以后就引用这个path来编译和运行代码,省心省力

ant的资料google一下,到处都是。下面是几个推荐的地址:
http://ant.apache.org(官方站点)
http://www.chedong.com/tech/ant.html
http://www.huihoo.com/java/ant.html

7.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: zcjl
Posted on: 2005-09-28 09:16

另外,Yulimin的blog有一篇介绍用-Djava.ext.dir属性来指定lib文件夹的方式:
http://iamin.blogdriver.com/iamin/715583.html

这样做也可以达到目的,至于是否会带来什么副作用,我就没有具体试验过

8.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-09-28 12:55

FAQ on ANT Building Process by Roseanne Zhang

9.Re:classpath的两个问题 ? [Re: zcjl] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-09-28 12:59

zcjl wrote:
另外,Yulimin的blog有一篇介绍用-Djava.ext.dir属性来指定lib文件夹的方式:
http://iamin.blogdriver.com/iamin/715583.html

这样做也可以达到目的,至于是否会带来什么副作用,我就没有具体试验过


Not recommended!

10.Re:classpath的两个问题 ? [Re: gongshi] Copy to clipboard
Posted by: zcjl
Posted on: 2005-09-28 15:19

gongshi wrote:
Not recommended!


can you tell us the reason?

11.Re:classpath的两个问题 ? [Re: snooopy] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-09-30 11:44

If you have heard and claimed the famous programmer statement:

It works on my machine! Wink

Then you at least have some real life experience of programming. You should know why?

Strictly to say, you should not even set the CLASSPATH variable in your environment, but set by your ant, make, batch, shell script. Since every machine could be set differently. The program works on your machine does not mean it will work on other machine.

The worst case scenario is put the necessary jars into java.ext.dir, jre/lib/ext. Since you might work on different Java programs, then you don't really know or remember which jar is for which app.

Someone might say I set my own java.ext.dir. Yes, that is cleaner than the jvm/lib/ext. However, you need a batch/shell script to run your Java program again. Then why not to use ant at the first place?????

Ant is free, ant is good, ant is platform independent. Ant is the standard now, if you don't want to go to maven. Big Smile.

Ant has a little steep learning curve, but still not hard.

Start to learn ant now!!!!!

Thanks!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923