如何创建一个可执行的jar文件,该文件可以执行同一包中其他java类的方法
文件夹结构的图像: 我正在尝试从eclipse创建一个可执行的jar文件。。我在java包中有3个类,其中一个类是主类,另外2个类包含主类中的一些方法。我已经在线签入并创建了一个jar文件,但它没有执行其他类方法的输出。。我知道的是,我在eclipse中运行了相同的程序,它给出了输出,但当我从可执行jar文件运行它时,它并没有执行其他类的方法。那么,有人能帮我创建一个jar文件吗 我已经按照此站点中的步骤创建了一个jar文件 当用户单击Generate按钮时,它将开始执行同一类中的方法,在该方法中,我调用另一个类方法 方法 生成按钮执行代码如何创建一个可执行的jar文件,该文件可以执行同一包中其他java类的方法,java,Java,文件夹结构的图像: 我正在尝试从eclipse创建一个可执行的jar文件。。我在java包中有3个类,其中一个类是主类,另外2个类包含主类中的一些方法。我已经在线签入并创建了一个jar文件,但它没有执行其他类方法的输出。。我知道的是,我在eclipse中运行了相同的程序,它给出了输出,但当我从可执行jar文件运行它时,它并没有执行其他类的方法。那么,有人能帮我创建一个jar文件吗 我已经按照此站点中的步骤创建了一个jar文件 当用户单击Generate按钮时,它将开始执行同一类中的方法,在该
我将总结解决方案。 依赖库未打包到JAR中。因此,导致
NoClassDefFoundError:org/jsoup/Jsoup
因此,使用maven重新打包jsoup依赖项
解决了这个问题
一个快速的解决方法是通过IDE复制生成的jar。Hi and welcome。你能分享你的代码吗?您是如何运行可执行jar的?显示您如何执行它的示例,以及该示例和Eclipse的输出是什么。您是否发现了与Main()相关的错误。是否调用了main(),并为其他两个类获得了ClassNotFoundException。如果main()出现问题,请尝试使用-java-cp MyJar.jar com.mycomp.myproj。ClassWithMainMethod@DarkMatter,我已经用图片和代码更新了我的问题。。。为方便起见,我在代码中添加了一条注释,该方法将在其中开始执行…@pratekpande,因为我是新手,我不知道如何查看jar执行日志..你能帮我获取jar执行日志吗..是的,最后当我从cmd运行它时。。我得到了执行日志,但它没有得到类的依赖项。。它需要JSoup,执行失败,出现
NoClassDefFoundError:org/JSoup/JSoup
bj.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JLabel j = null;
url = userInput.getText();
if(!url.startsWith("http") || !url.startsWith("https")){
url="";
}
locType = combo.getSelectedItem().toString();
tagName = comboTags.getSelectedItem().toString();
boolean executeOutput = false;
JPanel output = new JPanel(new BorderLayout(4, 4));
output.setPreferredSize(new DimensionUIResource(500, 350));
JPanel resOpJP = new JPanel(new GridLayout(0, 1, 4, 4));
resOpJP.add(new JLabel("Output : ", SwingConstants.LEFT));
JButton downLoad = new JButton("Download in file");
JPanel Message = new JPanel();
if (url.isEmpty()
&& (selectedFile != null && selectedFile.endsWith(".html") && !selectedFile.isEmpty())) {
j = new JLabel("Selected File/URL is " + selectedFile, SwingConstants.RIGHT);
inputPath = selectedFile;
executeOutput = true;
} else if ((url.startsWith("http") || url.startsWith("https"))
&& (selectedFile == null || selectedFile.isEmpty())) {
j = new JLabel("Selected File/URL is " + url, SwingConstants.RIGHT);
inputPath = url;
executeOutput = true;
} else if ((url==null ||url.isEmpty()) && (selectedFile == null || selectedFile.isEmpty())) {
JOptionPane.showMessageDialog(Message, "Please provide a valid html file / provide a URL", "Error",
JOptionPane.ERROR_MESSAGE);
} else if (selectedFile != null && !selectedFile.isEmpty()) {
if (selectedFile.contains("html") && !(new File(selectedFile).exists())) {
JOptionPane.showMessageDialog(Message, "Please provide a valid html file path", "Error",
JOptionPane.ERROR_MESSAGE);
selectedFile = "";
} else if (!selectedFile.endsWith(".html") && (new File(selectedFile).exists())) {
JOptionPane.showMessageDialog(Message, "Please provide a valid html file", "Error",
JOptionPane.ERROR_MESSAGE);
selectedFile = "";
}
} else if (!url.isEmpty() && (!url.startsWith("http") || !url.startsWith("https"))) {
JOptionPane.showMessageDialog(Message, "Please provide a valid URL", "Error",
JOptionPane.ERROR_MESSAGE);
}
if (locType.contains("Select Locator") || tagName.contains("Select Tag")) {
executeOutput = false;
JOptionPane.showMessageDialog(Message, "Locator Type and Tag is mandatory", "Error",
JOptionPane.ERROR_MESSAGE);
} else if (!locType.contains("Select Locator") && !tagName.contains("Select Tag")) {
executeOutput = true;
}
if (executeOutput) {
///*****This is the step where other class method invoke***///
xpathUI.expectedOutput = generateOutput(inputPath, tagName);
if (xpathUI.expectedOutput.equals("No html tag found in the provided html")) {
JOptionPane.showMessageDialog(new JPanel(), xpathUI.expectedOutput, "Information",
JOptionPane.WARNING_MESSAGE);
} else if(xpathUI.expectedOutput.contains("Error")){
JOptionPane.showMessageDialog(new JPanel(), xpathUI.expectedOutput, "Error Message",
JOptionPane.ERROR_MESSAGE);
}else {
downLoad.addActionListener(new ActionListener() {
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e) {
JFrame jF = new JFrame();
jF.setSize(300, 300);
choose = new JFileChooser();
choose.showSaveDialog(jF);
choose.setCurrentDirectory(new File(System.getProperty("user.home")));
choose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
try {
String saveFile = "";
try {
saveFile = choose.getSelectedFile().getAbsolutePath();
System.out.println(saveFile);
} catch (Exception ex) {
saveFile = "";
}
if ((saveFile != null || !saveFile.isEmpty())
&& !saveFile.split(".txt")[0].isEmpty()) {
FileOutputStream fout = new FileOutputStream(new File(saveFile));
fout.write(xpathUI.expectedOutput.getBytes());
fout.flush();
fout.close();
if (new File(saveFile).exists()) {
JOptionPane.showMessageDialog(new JPanel(),
"Locator file saved successfully at :\n" + saveFile,
"Confirmation Message", JOptionPane.INFORMATION_MESSAGE);
}
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
j.setFont(new FontUIResource("Arial", Font.PLAIN, 10));
resOpJP.add(j);
output.add(resOpJP, BorderLayout.LINE_START);
JPanel text = new JPanel(new GridLayout(0, 1));
JTextArea jta = new JTextArea();
jta.setText("");
jta.setText(xpathUI.expectedOutput);
jta.setLineWrap(true);
jta.setRows(15);
jta.setColumns(1);
text.add(jta);
output.add(text, BorderLayout.PAGE_END);
JOptionPane.showOptionDialog(null, output, "XPATH Generator : Output", JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, new Object[] { downLoad }, null);
}
}
}
});
NoClassDefFoundError:org/jsoup/Jsoup