错误:找不到或加载主类我在编译和运行我的Java代码时遇到了困难,目的是允许我为Vensim提供一个共享对象,这是一个模拟建模包。以下代码编译时没有错误:javac -d . -cp ./apache-log4j-1.2.16/log4j-1.2.16.jar:./vensim.jar SpatialModel.java
VensimHelper.java VensimException.java VensimContextRepository.java但是,当我尝试运行以下代码时:java -cp ./apache-log4j-1.2.16/log4j-1.2.16.jar:./vensim.jar SpatialModel vars我得到以下错误:“错误:找不到或加载主类空间模型”。我的SpatialModel.java代码确实包含一个‘main’方法(下面),所以我不知道问题是什么-有人能帮我吗?谢谢。import java.io.File;import java.text.NumberFormat;import java.util.ArrayList;import java.util.Arrays;import java.util.List;
import org.apache.log4j.Logger;public class SpatialModel {
private VensimHelper vh;
public static final String DLL_LIBNAME_PARAM = "vensim_lib_nam";
public static final String MODEL_PATH_PARAM = "vensim_model_path";
private final static int VENSIM_CONTEXT_CREATION_MAX_FAILURE_COUNT = 10;
public SpatialModel() throws SpatialException {
String libName = System.getProperty(DLL_LIBNAME_PARAM);
String modelPath = System.getProperty(MODEL_PATH_PARAM);
if(libName == null || libName.trim().equals("")) {
log.error("Vensim library name has to be set with -D" + DLL_LIBNAME_PARAM);
throw new SpatialException("Vensim library name has to be set with -D" + DLL_LIBNAME_PARAM);
}
if(modelPath == null || modelPath.trim().equals("")) {
log.error("Model path has to set with -D" + MODEL_PATH_PARAM);
throw new SpatialException("Model path ahs to be set with -D" + MODEL_PATH_PARAM);
}
for (int i = 0; i < VENSIM_CONTEXT_CREATION_MAX_FAILURE_COUNT && vh == null; i++) {
try {
log.info("creating new vensim helper\n\tdll lib: " + libName + "\n\tmodel path: " + modelPath);
vh = new VensimHelper(libName, modelPath);
} catch (Throwable e) {
log.error("An exception was thrown when initializing Vensim, try: " + i, e);
}
}
3 回答
潇潇雨雨
TA贡献1833条经验 获得超4个赞
package thepackagename;public class TheClassName { public static final void main(String[] cmd_lineParams) { System.out.println("Hello World!"); } }
java -classpath . TheClassName
Error: Could not find or load main class TheClassName
java -classpath . thepackagename.TheClassName
thepackagename
.
thepackagename
TheClassName
thepackagename.TheClassName
TheClassName
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
HelloWorld
d:\sample
java -cp d:\sample HelloWorld
java -cp . HelloWorld
添加回答
举报
0/150
提交
取消