java 批量导入 java classpath 命令行

java 6 有通配符 , 即使不是java 6 也可以根据 shell的强大功能自动实现 批量

可以替代 ant 了 ,麻烦;;

我自己的案例:

以前用ant :

 

后来直接用java

java -cp "/home/work/dataio/WEB-INF/lib/*"   com.baidu.adcoup.base.task.TaskScheduler
Exception in thread "main" java.lang.IllegalArgumentException: The validated expression is false
        at org.apache.commons.lang.Validate.isTrue(Validate.java:158)
        at com.baidu.adcoup.base.task.TaskScheduler.main(TaskScheduler.java:12)
=========
结合eclipse的 remote project ( 先学会如何创建 create  remote project ,再 到 java 视图下 , 右键项目 , 到 facets , 修改成 java 项目 ) , 可以实现linux 启动 debug  编辑 java ;;
不用再羡慕vim ;;
不用再怕直接调试linux的麻烦 ;;
彻底摆脱部署噩梦 ,执行噩梦;;
彻底摆脱编译噩梦;(依靠svn 同步代码, 但linux上编译整个项目 如何编译呢?  )
彻底摆脱要依靠hudson 自动部署,(
手工部署A 1 .先windos编译 2. scp到linux( 这个过程超级麻烦 ,打包 , sz 
手工部署B,  1 先ci代码 2.用svn下载下来,  3.然后借助ant 或者maven 进行 依赖编译 多个java )  ;
 
maven+svn解决了轻量级更新代码+ compile 依赖控制;
或者借助于ant编译普通java项目;; 
 
从此 java 也是 解释性语言, 而且方便的 import 管理 ,比 python等语言高端不少 ;
不用再羡慕 python , 也不要羡慕vim的超多高级功能
==============================
 

If using Java 6 or later, classpath wildcards are a part of the JVM.

java -cp "Test.jar;lib/*" my.package.MainClass

Key gotchas:

  1. Use quotes
  2. Use * only, not *.jar

The above example and gotchas are from other answers on this page. (Thanks davorp et al & Wim Deblauwe)

From the Classpath document section entitled, Understanding class path wildcards:

Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

A class path entry that contains * will not match class files. To match both classes and JAR files in a single directory foo, use either foo;foo/* or foo/*;foo. The order chosen determines whether the classes and resources in foo are loaded before JAR files in foo, or vice versa.

Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo, not in foo/barfoo/baz, etc.

The order in which the JAR files in a directory are enumerated in the expanded class path is not specified and may vary from platform to platform and even from moment to moment on the same machine. A well-constructed application should not depend upon any particular order. If a specific order is required then the JAR files can be enumerated explicitly in the class path.

Expansion of wildcards is done early, prior to the invocation of a program's main method, rather than late, during the class-loading process itself. Each element of the input class path containing a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory foo contains a.jarb.jar, andc.jar, then the class path foo/* is expanded into foo/a.jar;foo/b.jar;foo/c.jar, and that string would be the value of the system property java.class.path.

The CLASSPATH environment variable is not treated any differently from the -classpath (or -cp) command-line option. That is, wildcards are honored in all these cases. However, class path wildcards are not honored in the Class-Path jar-manifest header.

If you cannot use wildcards, bash allows the following syntax (where lib is the directory containing all the Java archive files):

java -cp $(echo lib/*.jar | tr ' ' ':')

(Note that using a classpath is incompatible with the -jar option. See also: Execute jar file with multiple classpath libraries from command prompt)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值