使用javac/java手动编译并运行多个软件包 [英] Manually compile and run multiple packages using javac/java

查看:113
本文介绍了使用javac/java手动编译并运行多个软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我具有以下文件夹结构:

Let's say I have the following folder structure:

\ src \ com \ proj \ pp1 \ stuff,其中com.proj.pp1com.proj.pp1.stuff是我拥有的两个软件包:

\src\com\proj\pp1\stuff where com.proj.pp1 and com.proj.pp1.stuff are the two packages I have:

    -src
      -com
        -proj
          -pp1
             tester.java
             -stuff
                some other .java's

成为tester.java中的主要功能,并使用/stuff中声明的类.

Being the main function in tester.java, and using the classes declared in /stuff.

tester.java中,我以这种方式声明了导入:

In tester.java I declare the imports that way:

package com.proj.pp1;    
import com.proj.pp1.*;

在根据东西声明的所有文件中:

And in all the files declared under stuff:

package com.proj.pp1.stuff;

没有任何进口.

/pp1文件夹中,我能够执行.class的以下操作:

I'm able to get the .class's doing the following, being in /pp1 folder:

javac tester.java stuff/*.java

但是当我尝试运行测试器类时:

But when I try to run the tester class:

java tester

它给了我错误输出: 找不到或加载主类测试器 和同样的事情,如果我尝试java com.proj.pp1.tester

It gives me the error output: Could not find or load main class tester and the very same thing if I try java com.proj.pp1.tester

您认为可能是什么实际问题?

What do you think could be the actual problem?

推荐答案

javac文件作为参数,因此应该是

javac takes files as arguments, so it should be

cd src
javac com/proj/pp1/tester.java

那应该编译tester.java和所有相关的类.

That should compile tester.java and all related classes.

java以主要的 class 作为参数,因此要运行它,请执行以下操作:

and java takes the main class as argument, so to run it you do:

java com.proj.pp1.tester

(调用java com.proj.pp1.tester时,请确保com/proj/pp1/tester.class存在.)

(When you invoke java com.proj.pp1.tester make sure com/proj/pp1/tester.class exists.)

您可能希望阅读javac-d选项,以避免将类放在源目录中.

You might want to read up on -d option for javac to avoid putting your classes in the source directory.

这篇关于使用javac/java手动编译并运行多个软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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