在classpath中指定log4j [英] specifying log4j in classpath

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

问题描述

我相信这是我可以编译和运行使用外部库的文件的方法。我正在使用Windows。

I believe this is how I can compile and run a file that uses external library. I'm using Windows.

top level directory
|
|-log4-1.2.17.jar
|-MyApp.java
|-com
     |-foo
          |-Bar.java

编译

javac -cp log4j-1.2.17.jar;. com\foo\Bar.java
javac -cp log4j-1.2.17.jar;"com\foo";. MyApp.java

执行

java -cp log4j-1.2.17.jar;"com\foo";. MyApp

编译本身失败。

推荐答案

简单的批处理脚本,用于编译所有项目

simple batch script, for compiling all your project

set COMPILED_CLASSES=.\
set TEMP_FILE=temp
dir .\*.java /s /B > %TEMP_FILE%
javac -classpath log4j-1.2.17.jar;%COMPILED_CLASSES% -d %COMPILED_CLASSES% @%TEMP_FILE%
rm %TEMP_FILE%

将其添加到顶级目录并运行

编辑

一步一步

add it to top level dir and run
EDIT
step by step

javac ./com/foo/Bar.java -classpath log4j-1.2.17.jar  

next

javac ./MyApp.java -classpath log4j-1.2.17.jar;./  

run

java -classpath log4j-1.2.17.jar;./ MyApp  

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

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