Java classpath and directories
2016-04-16 11:36
549 查看
The java classpath and directories has always been quite a sad story. Of course you were always able to pass a directory of classes to the jvm like this:
But what you usually deal with these days are jars. Often quite a bunch of them. So fair enough – let’s add a directory with jars as well:
Up until java 5 all you got was a ClassNotFoundException because java did not search for jars but classes in there. It just ignored the jars. So what pretty much everyone ended up doing is providing yet
another shell script to build up the classpath and pass it to the jvm via command line. Of course for bigger projects this let to…
I guess you see where I am going …an unmanageable mess of a command line. But thankfully times have changed. Starting with java 6 (mustang) you
can now use wildcards in the classpath:
Naturally this means that the order of the jars is implicit. Which in turn means you need to be extra careful when there are classpath clashes. But in general I think this is a nice feature that should have been there from day one …and I just found out about
it.
java -classpath classes Main
But what you usually deal with these days are jars. Often quite a bunch of them. So fair enough – let’s add a directory with jars as well:
java -classpath classes:lib Main
Up until java 5 all you got was a ClassNotFoundException because java did not search for jars but classes in there. It just ignored the jars. So what pretty much everyone ended up doing is providing yet
another shell script to build up the classpath and pass it to the jvm via command line. Of course for bigger projects this let to…
java -classpath lib/commons-logging-1.1.1.jar:lib/commons-jci-core-1.0.jar:commons-io-1.2.jar:lib/junit-3.8.2.jar:lib/maven-project-2.0.8.jar:lib/rhino-js-1.6.5.jar: ...
I guess you see where I am going …an unmanageable mess of a command line. But thankfully times have changed. Starting with java 6 (mustang) you
can now use wildcards in the classpath:
java -classpath classes:lib/'*' Main
Naturally this means that the order of the jars is implicit. Which in turn means you need to be extra careful when there are classpath clashes. But in general I think this is a nice feature that should have been there from day one …and I just found out about
it.
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树