好吧,我不确定这是否可行,可能听起来也很愚蠢,请原谅我,但是是否可以说,例如我正在使用 netbeans,并且我创建了各种项目,并且每个项目都有一个包含某些程序的包,我是否可以创建一个新项目和新包,并将它们在一个文件中调用所有上述包并运行它?
例如,我有一个十六进制到十进制转换器,而我的另一个项目是十进制到十六进制,并且我创建了一个名为转换器的新项目,并且其中包含 if 和 else 函数
我说 sout("1) 十六进制到十进制转换器 2) 十进制到十六进制,输入数字以使用转换器");
if(userinput=='1')
{
call the hexadecimal to decimal convertor
}
elseif(userinput=='2')
{
call the deciminal to hexadecimal convertor
}
else
sout("invaild")
};
是否可以在一个项目中调用外部项目或包?
谢谢。
最佳答案
第一:这是可能的。
就我个人而言,我从未使用过 Netbeans,只使用过 Eclipse,但这应该可以工作 ( see original article ):
[...] go to properties of the main project (right-click on the project and choose properties). Go to the Libraries section and choose Add Project. Now you need to find the project folder on your disk and by selecting it, the project's jar is added to the compile classpath
当然,您仍然需要导入 .java 源文件中的包才能使用执行转换的相应类。这可能如下所示:
import com.test.converter.hex.*;
import com.test.converter.dec.*;
class YourClass {
// your code here
}
第二:为什么你想将你的工作分成单独的项目?将其放在不同的包甚至不同的类中还不够吗?通常,如果您想以不同的方式分发它们,则将其拆分为不同的项目是有意义的,但这里似乎并非如此。
关于java - 从不同的项目调用不同的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24218002/