adding classpath in linux

后端 未结 5 1828
梦毁少年i
梦毁少年i 2020-12-03 02:11
export CLASSPATH=.;../somejar.jar;../mysql-connector-java-5.1.6-bin.jar
java -Xmx500m folder.subfolder../dit1/some.xml
cd ..

is the above statement

5条回答
  •  自闭症患者
    2020-12-03 02:44

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

    • 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.

    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
    

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

提交回复
热议问题