从其他目录导入Java [英] Java import from other directory
问题描述
我正在使用Java构建企业服务总线(ESB)。我不会进入
详细信息但是我必须构建多个使用相同类的服务器。
I am building a Enterprise Service Bus (ESB) with Java. I won't get into details But I have to build multiple servers who make use of the same classes.
我有以下目录结构:
/server1
-Main.java
/server2
-Main.java
/com
-Database.java
我想从 Main.java
类导入,例如 Database.class
。
但当然以下陈述不起作用:
I want to import from the Main.java
class for example the Database.class
.
But of course the following statements won't work:
import com.Database;
我在命令行中使用javac编译器(所以不要使用eclipse的东西或其他任何东西。只需TextMate和命令行)。我通过在com目录的服务器中创建一个符号链接找到了一个(非常愚蠢的)解决方案。但这并不是一个理想的解决方案。
I am working with the javac compiler in the command line (so not eclipse stuff or whatever. just TextMate and the command line). And I found a (pretty stupid) solution by creating a symbolic link in the servers to the com directory. But that is not really an ideal solution.
有人有更好的吗?
推荐答案
设置你的classpath包含包含 com
目录的目录。
Set up your classpath to include the directory that contains the com
directory.
我讨厌消极,但如果你需要帮助,然后写一个ESB可能高于你目前的技能水平。
And I hate to be negative, but if you need help with that, then writing an ESB is probably above your current skill level.
这篇关于从其他目录导入Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!