找不到自己类Java的符号

时间:2012-11-14 16:51:20

标签: java

我意识到这已经被问了很多,但无法从这些答案中找出问题。

我有一个抽象类Task:

package crowdtrust;

public abstract class Task
{

  public enum Type
  {
    BinaryImageClassification;
  };

  public abstract void assignCrowd();
};

执行任务:

package crowdtrust;

import java.util.Collection;
import java.util.List;

public class BinaryTask extends Task
{

  private List<SubTask> subtasks;

  public BinaryTask(String name, String question)
  {
    super();
    this.name = name;
    this.question = question;
  }

  public boolean assignSubtask(SubTask s)
  {
      return subtasks.add(s);
  }

  public void assignCrowd()
  {
    //TODO 
  }

};

和子任务类:

package crowdtrust;
public class SubTask {
  //not important
}

这些都在ct / src / crowdtrust

从ct我运行这个makefile:

CONTEXT   = webapps/ROOT
SRCDIR    = src

CLASSDIR  = $(CONTEXT)/WEB-INF/classes
LIBDIR    = $(CONTEXT)/WEB-INF/lib

JAVAC     = javac

SOURCES   = $(wildcard $(SRCDIR)/crowdtrust/*.java)
CLASSES   = $(SOURCES:.java=.class)

all: install clean

clean:
    rm -f $(CLASSES)

install: $(CLASSES)
    install -m600 $(CLASSES) $(CLASSDIR)/crowdtrust

%.class: %.java
    $(JAVAC) -cp $(LIBDIR) $<

得到这些(加上更相似的)错误:

javac -cp webapps/ROOT/WEB-INF/lib src/crowdtrust/BinaryTask.java
src/crowdtrust/BinaryTask.java:6: cannot find symbol
symbol: class Task
public class BinaryTask extends Task
                                ^
src/crowdtrust/BinaryTask.java:9: cannot find symbol
symbol  : class SubTask
location: class crowdtrust.BinaryTask
  private List<SubTask> subtasks;
               ^

任何想法导致错误的原因是什么?

1 个答案:

答案 0 :(得分:4)

我认为它没有正确找到依赖项,而BinaryTask正在Task之前编译。要解决此问题,请在make文件中定义显式依赖关系:

  SOURCES = Task.java SubTask.java BinaryTask.java
  BinaryTask.class: Task.class SubTask.class