在linux中添加classpath [英] adding classpath in linux

查看:343
本文介绍了在linux中添加classpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

export CLASSPATH=.;../somejar.jar;../mysql-connector-java-5.1.6-bin.jar
java -Xmx500m folder.subfolder../dit1/some.xml
cd ..

是上面的设置声明linux中已存在的类路径的类路径是否正确

is the above statement for setting the classpath to already existing classpath in linux is correct or not

推荐答案

我不喜欢设置CLASSPATH。 CLASSPATH是一个全局变量,因此它是邪恶的:

I don't like setting CLASSPATH. CLASSPATH is a global variable and as such it is evil:


  • 如果你在一个脚本中修改它,突然一些java程序将停止工作。

  • 如果你为你运行的所有东西放置了库,它就会变得混乱。

  • 如果两个不同的应用程序使用不同,你会遇到冲突同一个库的版本。

  • 没有性能提升,因为CLASSPATH中的库没有共享 - 只是它们的名称是共享的。

  • 如果你把点(。)或任何其他相对路径放在CLASSPATH中,这意味着每个地方都有不同的东西 - 这肯定会引起混淆。

  • If you modify it in one script, suddenly some java programs will stop working.
  • If you put there the libraries for all the things which you run, and it gets cluttered.
  • You get conflicts if two different applications use different versions of the same library.
  • There is no performance gain as libraries in the CLASSPATH are not shared - just their name is shared.
  • If you put the dot (.) or any other relative path in the CLASSPATH that means a different thing in each place - that will cause confusion, for sure.

因此,首选的方法是设置每次运行jvm的类路径,例如:

Therefore the preferred way is to set the classpath per each run of the jvm, for example:

java -Xmx500m -cp ".:../somejar.jar:../mysql-connector-java-5.1.6-bin.jar"    "folder.subfolder../dit1/some.xml

如果它变长,标准程序是将其包装在bash或批处理脚本中以节省输入。

If it gets long the standard procedure is to wrap it in a bash or batch script to save typing.

这篇关于在linux中添加classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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