【发布时间】:2013-06-19 02:11:15
【问题描述】:
问题:
我应该如何只编译一个类?如何将其放入类文件(我已创建)? Eclipse 不就是在运行时自动编译所有的类吗?
背景故事:
我正在关注tutorial,它告诉我:
将编译好的类放入WEB-INF/classes。
班级在哪里:
package org.odata4j.tomcat;
import java.util.Properties;
import org.core4j.Enumerable;
import org.core4j.Func;
import org.core4j.Funcs;
import org.odata4j.producer.ODataProducer;
import org.odata4j.producer.ODataProducerFactory;
import org.odata4j.producer.inmemory.InMemoryProducer;
public class ExampleProducerFactory implements ODataProducerFactory {
@Override
public ODataProducer create(Properties properties) {
InMemoryProducer producer = new InMemoryProducer("example");
// expose this jvm's thread information (Thread instances) as an entity-set called "Threads"
producer.register(Thread.class, Long.class, "Threads", new Func<Iterable<Thread>>() {
public Iterable<Thread> apply() {
ThreadGroup tg = Thread.currentThread().getThreadGroup();
while (tg.getParent() != null)
tg = tg.getParent();
Thread[] threads = new Thread[1000];
int count = tg.enumerate(threads, true);
return Enumerable.create(threads).take(count);
}
}, Funcs.method(Thread.class, Long.class, "getId"));
return producer;
}
}
【问题讨论】:
-
"Doesn't Eclipse just automatically compile all the classes at runtime?"-- Eclipse 会在您键入时自动编译。这是它可以快速识别编译错误的一种方式。如果你查看 bin 子目录,你会看到类文件。 -
通常 Eclipse 会为您执行此操作。如果您转到 Eclipse 构建路径(右键单击项目上的属性 -> 构建路径)然后选择“源”,它应该会显示一个输出文件夹。
-
你可以使用
javac来编译你想要的任何java文件,如果它在你的路径上。 -
@HovercraftFullOfEels 注意eclipse默认编译,但不需要。