[英]How do I link two Java files together during compilation using GCJ?
My apologies as I'm very much a "Java noob." 我很抱歉,因为我非常喜欢“Java noob”。 Anyways, I think I've dumbed this problem down sufficiently to ask in a way that is straight-forward and will get me the answer I want.
无论如何,我认为我已经足够愚蠢地解决这个问题,以一种直截了当的方式提出问题,并且会得到我想要的答案。 Let's say I have two files, both in my home directory, as follows:
假设我的主目录中有两个文件,如下所示:
Test.java: Test.java:
class Test
{
public static void main(String args[])
{
Test2.test();
}
}
and Test2.java: 和Test2.java:
class Test2
{
public static void test()
{
System.out.println("Hello World!");
}
}
Now if I leave these files as is, when I run " gcj Test.java --main=Test
", naturally I get an error saving Test2 is undefined. 现在,如果我按原样保留这些文件,当我运行“
gcj Test.java --main=Test
”时,自然会出现错误,保存Test2未定义。 But I have no idea what I need to add to tell it where to find Test2. 但我不知道我需要添加什么来告诉它在哪里找到Test2。 I tried adding "
import Test2;
", " import Test2.*;
", and " import Test2.java;
" to the top of Test.java, but clearly I'm not on the right track here. 我尝试将“
import Test2;
”,“ import Test2.*;
”和“ import Test2.java;
”添加到Test.java的顶部,但显然我在这里没有走上正轨。 What do I need to do to link these files together and get it to compile? 我需要做些什么才能将这些文件链接在一起并进行编译?
(Stuff about classpath removed) gcj doesn't follow normal java rules (删除了类路径的东西)gcj不遵循普通的java规则
Use: 采用:
gcj *.java --main=Test
instead of what you supplied, it works. 而不是你提供的,它的工作原理。
But still--put your stuff in packages and specify a classpath for anything beyond testing. 但仍然 - 将你的东西放在包中,并为测试之外的任何东西指定一个类路径。
Better yet, use Eclipse with a gcj plugin! 更好的是,使用带有gcj插件的 Eclipse !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.