使用javac从不同的目录编译文件,引用一个依赖的jar文件? [英] compile files from different directories with javac, referring a depending jar file?
问题描述
我有以下设置:
我有4个包:
- root / src / mail - 有一些java文件
- root / src /有一些java文件
- root / src / main - 只有一个java文件Main.java
我也有以下文件
- root / bin - 用于存储.class文件的文件夹
- root / mail.jar - 在我的代码中使用重要类的jar文件
输入终端命令,编译root / src / main / Main.java并将类文件放在根/ bin位置。
Within the root, I would like to enter a terminal command which compiles root/src/main/Main.java and puts the class files in the root/bin location.
有人可以向我显示命令做这个?我在Mac(运行Leopard)。
Can someone show me the command to do this? I'm on a Mac (running Leopard).
推荐答案
这是一个班轮:
cd /xyz/root
rm -rf bin/*
javac -d bin -classpath mail.jar -sourcepath src main/Main.java
或者,您可以使用绝对目录名:
Alternatively, you could use absolute directory names:
rm -rf /xyz/root/bin/*
javac -d /xyz/root/bin -classpath /xyz/root/mail.jar \
-sourcepath /xyz/root/src /xyz/root/ main/Main.java
参考Ant你说我宁愿保持简单。
In reference to Ant you said "I would rather keep it simple.".
事实上,从长远来看,创建一个简单的简单的Ant build.xml
文件。另一种是一堆非便携式脚本或批处理文件...或大量输入。
In fact in the long term it is simpler to create a simple Ant build.xml
file. The alternative is a bunch of non-portable scripts or batch file ... or lots of typing.
要运行应用程序,假设您仍然位于 / xyz / root
目录中:
To run the application, assuming that you are still in the /xyz/root
directory:
java -classpath bin:mail.jar main.Main
Or on Windows:
java -classpath bin;mail.jar main.Main
或者修改上面的代码以在classpath参数中使用绝对路径名;例如
Or modify the above to use absolute pathnames in the classpath argument; e.g.
java -classpath /xyz/root/bin:/xyz/root/mail.jar main.Main
这篇关于使用javac从不同的目录编译文件,引用一个依赖的jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!