我的项目Java代码有一些语法错误,错误的包名,如下所示:
// below line make java problem, The declared package "com.test.as.utils" does not match the expected package "com.test.as"
package com.test.as.utils;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.pointi.ivr.FileWatchdog;
import com.pointi.ivr.FileWatchdogListener;
import com.pointi.ivr.FileWatchdogThread;
public abstract class AbstractReloadConf implements FileWatchdogListener {
private static Logger logger = LoggerFactory.getLogger(AbstractReloadConf.class);
protected FileWatchdogThread watchdogThread;
synchronized
private void initialize(String configFile) throws Exception {
watchdogThread = new FileWatchdogThread("ConfigWatchdog");
watchdogThread.addFileWatchdog(new FileWatchdog(configFile));
watchdogThread.setFileWatchdogListener(this);
watchdogThread.setDelay(1000);
}
public void configureAndStart(String configFile) throws Exception {
initialize(configFile);
watchdogThread.start();
parseConfigFile(new File(configFile));
}
@Override
public void onChanged(File file) {
try {
parseConfigFile(file);
} catch (Exception e) {
logger.error("", e);
}
}
protected abstract void parseConfigFile(File file) throws Exception;
}
另一个类使用这个抽象类进行扩展,也会导致Java错误。如下所示:
package com.test.as.vmsc.server;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.ini4j.Wini;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.test.ivr.AppConfig;
// below line make java problem,The import com.test.as.utils cannot be resolved
import com.test.as.utils.AbstractReloadConf;
// below line make java problem, AbstractReloadConf cannot be resolved to a type
public class SceVmscReloadConf extends AbstractReloadConf {
private static Logger logger = LoggerFactory.getLogger(SceVmscReloadConf.class);
private static SceVmscReloadConf singletone = new SceVmscReloadConf();
private static final List<String> routeNumberList = new CopyOnWriteArrayList<String>();
public static SceVmscReloadConf getInstance() {
return singletone;
}
public void addRouteNumber(String routeNumber) {
routeNumberList.add(routeNumber);
}
@Override
// below line make java problem, The method parseConfigFile(File) of type SceVmscReloadConf must override or implement a supertype method
protected void parseConfigFile(File file) throws Exception {
Wini ini = new Wini(file);
String voicecertMode = ini.fetch("VOICECERT", "MODE", String.class);
if(voicecertMode != null) {
AppConfig.getInstance().setVariable("voicecertMode", voicecertMode);
} else {
AppConfig.getInstance().setVariable("voicecertMode", "0");
}
String voicecertOnlyDisable = ini.fetch("VOICECERT", "VOICE_ONLY_DISABLE", String.class);
if(voicecertOnlyDisable != null) {
AppConfig.getInstance().setVariable("voicecertOnlyDisable", voicecertOnlyDisable);
} else {
AppConfig.getInstance().setVariable("voicecertOnlyDisable", "0");
}
}
我认为这段代码将无法maven构建(目标是干净的,安装),因为它有一些java问题(错误的包路径)
但是maven构建成功了。
我不明白。我检查了pom.xml,但没有发现异常设置。
也许修改包路径正确的问题解决和代码使干净,但我想知道为什么这段代码成功maven构建尽管有java问题。
请将该类重命名为公共抽象类Test {} (T大写)更改导入MVN clean install =>应该没问题在eclipse菜单顶部单击project ->清洁=比;这应该会删除错误