我正在使用Netbeans 8.1,我按照这个指令Packaging and Distributing Java Desktop Applications来构建可执行文件(.jar),但是当我双击运行应用程序时,它会显示错误窗口,并显示消息“找不到主要班级“
以下是Netbeans用于构建.jar文件的配置:
在.jar文件中,它还包括声明主类的类。 我还需要做什么来构建可执行文件?
[编辑]
java -jar myfile.jar
jar -tvf myfile.jar
dir lib
这是diplayImage()函数
private String IMG_PATH = "src/images/";
public void displayImage(boolean isOK){
String imgOkFileName = "gateOK.png";
String imgNGFileName = "gateNG.png";
BufferedImage img = null;
if(isOK){
try{
img = ImageIO.read(new File(IMG_PATH+imgOkFileName));
}catch(IOException e){
Logger.getLogger(PTCMainFrame.class.getName()).log(Level.SEVERE, null, e);
}
Image dimg = img.getScaledInstance(lbImage.getWidth(), lbImage.getHeight(),
Image.SCALE_SMOOTH);
ImageIcon image = new ImageIcon(dimg);
if(image == null) lbImage.setText("Image not found");
else{
lbImage.setIcon(image);
}
}else{
try{
img = ImageIO.read(new File(IMG_PATH+imgNGFileName));
}catch(IOException e){
Logger.getLogger(PTCMainFrame.class.getName()).log(Level.SEVERE, null, e);
}
Image dimg = img.getScaledInstance(lbImage.getWidth(), lbImage.getHeight(),
Image.SCALE_SMOOTH);
ImageIcon image = new ImageIcon(dimg);
if(image == null) lbImage.setText("Image not found");
else{
lbImage.setIcon(image);
}
}
}