ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]
java.lang.NoClassDefFoundError: Could not initialize class org.apache.jmeter.gui.util.FileDialoger
线程中未捕获的异常
不能初始化类org.apache.jmeter.gui.util.FileDialoger
一、解决方法:
1、下载jmeter-plugins-manager-1.7.jar
官方下载: Install :: JMeter-Plugins.orghttps://jmeter-plugins.org/install/Install/
?csdn下载,是我从官网下载下来的:
https://download.csdn.net/download/c_lanxiaofang/85197545
?2、把jar包放在apache-jmeter-5.4.3\lib\ext文件夹下
?3、重新启动jmete.bat 即可
二、错误分析
报错代码如下:
2022-04-21 22:13:31,087 ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]
java.lang.NoClassDefFoundError: Could not initialize class org.apache.jmeter.gui.util.FileDialoger
at org.apache.jmeter.gui.util.FilePanelEntry.actionPerformed(FilePanelEntry.java:151) ~[ApacheJMeter_core.jar:5.4.3]
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972) ~[?:?]
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313) ~[?:?]
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) ~[?:?]
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) ~[?:?]
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) ~[?:?]
at com.github.weisj.darklaf.ui.button.DarkButtonListener.mouseReleased(DarkButtonListener.java:72) ~[darklaf-core-2.5.4.jar:2.5.4]
at java.awt.Component.processMouseEvent(Component.java:6626) ~[?:?]
at javax.swing.JComponent.processMouseEvent(JComponent.java:3389) ~[?:?]
at java.awt.Component.processEvent(Component.java:6391) ~[?:?]
at java.awt.Container.processEvent(Container.java:2266) ~[?:?]
at java.awt.Component.dispatchEventImpl(Component.java:5001) ~[?:?]
at java.awt.Container.dispatchEventImpl(Container.java:2324) ~[?:?]
at java.awt.Component.dispatchEvent(Component.java:4833) ~[?:?]
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948) ~[?:?]
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575) ~[?:?]
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516) ~[?:?]
at java.awt.Container.dispatchEventImpl(Container.java:2310) ~[?:?]
at java.awt.Window.dispatchEventImpl(Window.java:2780) ~[?:?]
at java.awt.Component.dispatchEvent(Component.java:4833) ~[?:?]
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) ~[?:?]
at java.awt.EventQueue$4.run(EventQueue.java:722) ~[?:?]
at java.awt.EventQueue$4.run(EventQueue.java:716) ~[?:?]
at java.security.AccessController.doPrivileged(AccessController.java:399) ~[?:?]
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) ~[?:?]
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97) ~[?:?]
at java.awt.EventQueue$5.run(EventQueue.java:746) ~[?:?]
at java.awt.EventQueue$5.run(EventQueue.java:744) ~[?:?]
at java.security.AccessController.doPrivileged(AccessController.java:399) ~[?:?]
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) ~[?:?]
at java.awt.EventQueue.dispatchEvent(EventQueue.java:743) ~[?:?]
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) [?:?]
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) [?:?]
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) [?:?]
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) [?:?]
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:?]
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) [?:?]
1、先看第三行报错内容:
at org.apache.jmeter.gui.util.FilePanelEntry.actionPerformed(FilePanelEntry.java:151) ~[ApacheJMeter_core.jar:5.4.3]
指向的是 ApacheJMeter_core.jar:5.4.3 的jar包中的 FilePanelEntry.java 类,首先我的jmeter是 5.4.3的版本,ApacheJMeter_core.jar 包位置在 \apache-jmeter-5.4.3\lib\ext
①把 ApacheJMeter_core.jar 解压查看源码
②在 \ApacheJMeter_core\org\apache\jmeter\gui\util 下可以查找到 FilePanelEntry.class
?
?
③ 在idea 或者eclipse 中可以打开 这个.class 文件
④ FilePanelEntry.class 源码如下:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package org.apache.jmeter.gui.util;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.JFactory;
public class FilePanelEntry extends HorizontalPanel implements ActionListener {
private static final long serialVersionUID = 280L;
private final JTextField filename;
private final JLabel label;
private final JButton browse;
private static final String ACTION_BROWSE = "browse";
private final List<ChangeListener> listeners;
private final String[] filetypes;
private boolean onlyDirectories;
public FilePanelEntry() {
this(JMeterUtils.getResString("file_visualizer_filename"));
}
public FilePanelEntry(String label) {
this(label, (ChangeListener)null);
}
public FilePanelEntry(String label, String... exts) {
this(label, (ChangeListener)null, exts);
}
public FilePanelEntry(String label, boolean onlyDirectories, String... exts) {
this(label, onlyDirectories, (ChangeListener)null, exts);
}
public FilePanelEntry(String label, ChangeListener listener, String... exts) {
this(label, false, listener, exts);
}
public FilePanelEntry(String label, boolean onlyDirectories, ChangeListener listener, String... exts) {
this.filename = new JTextField(10);
this.browse = new JButton(JMeterUtils.getResString("browse"));
this.listeners = new ArrayList();
this.onlyDirectories = false;
this.label = new JLabel(label);
if (listener != null) {
this.listeners.add(listener);
}
if (exts == null || exts.length == 1 && exts[0] == null) {
this.filetypes = null;
} else {
this.filetypes = new String[exts.length];
System.arraycopy(exts, 0, this.filetypes, 0, exts.length);
}
this.onlyDirectories = onlyDirectories;
this.init();
}
public final void addChangeListener(ChangeListener l) {
this.listeners.add(l);
}
private void init() {
this.add(this.label);
this.add(this.filename);
this.filename.addActionListener(this);
JFactory.small(this.browse);
this.add(this.browse);
this.browse.setActionCommand("browse");
this.browse.addActionListener(this);
}
public void clearGui() {
this.filename.setText("");
}
public void enableFile(boolean enable) {
this.browse.setEnabled(enable);
this.filename.setEnabled(enable);
}
public String getFilename() {
return this.filename.getText();
}
public void setFilename(String f) {
this.filename.setText(f);
}
private void fireFileChanged() {
Iterator var1 = this.listeners.iterator();
while(var1.hasNext()) {
ChangeListener cl = (ChangeListener)var1.next();
cl.stateChanged(new ChangeEvent(this));
}
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("browse")) {
JFileChooser chooser;
if (this.filetypes != null && this.filetypes.length != 0) {
chooser = FileDialoger.promptToOpenFile(this.filetypes, this.filename.getText(), this.onlyDirectories);
} else {
chooser = FileDialoger.promptToOpenFile(this.filename.getText(), this.onlyDirectories);
}
if (chooser != null && chooser.getSelectedFile() != null) {
this.filename.setText(chooser.getSelectedFile().getPath());
this.fireFileChanged();
}
} else {
this.fireFileChanged();
}
}
}
⑥ 报错指向的方法是 actionPerformed
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("browse")) {
JFileChooser chooser;
if (this.filetypes != null && this.filetypes.length != 0) {
chooser = FileDialoger.promptToOpenFile(this.filetypes, this.filename.getText(), this.onlyDirectories);
} else {
chooser = FileDialoger.promptToOpenFile(this.filename.getText(), this.onlyDirectories);
}
if (chooser != null && chooser.getSelectedFile() != null) {
this.filename.setText(chooser.getSelectedFile().getPath());
this.fireFileChanged();
}
} else {
this.fireFileChanged();
}
}
?2、第二行报错:
java.lang.NoClassDefFoundError: Could not initialize class org.apache.jmeter.gui.util.FileDialoger
无法初始化类 FileDialoger
NoClassDefFoundError错误的发生,是因为Java虚拟机在编译时能找到合适的类,而在运行时不能找到合适的类导致的错误。例如在运行时我们想调用某个类的方法或者访问这个类的静态成员的时候,发现这个类不可用,此时Java虚拟机就会抛出NoClassDefFoundError错误。
【报这个错有可能是classpath环境变量没有配好】
FileDialoger 源码:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package org.apache.jmeter.gui.util;
import java.awt.Component;
import java.io.File;
import java.util.Arrays;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.JMeterFileFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class FileDialoger {
private static String lastJFCDirectory = null;
private static JFileChooser jfc = new JFileChooser();
private static final Logger LOG = LoggerFactory.getLogger(FileDialoger.class);
private FileDialoger() {
}
public static JFileChooser promptToOpenFile() {
return promptToOpenFile((String)null);
}
public static JFileChooser promptToOpenFile(String existingFileName) {
return promptToOpenFile(new String[0], existingFileName);
}
public static JFileChooser promptToOpenFile(String existingFileName, boolean onlyDirectories) {
return promptToOpenFile(new String[0], existingFileName, onlyDirectories);
}
public static JFileChooser promptToOpenFile(String[] exts) {
return promptToOpenFile(exts, (String)null);
}
public static JFileChooser promptToOpenFile(String[] exts, String existingFileName) {
return promptToOpenFile(exts, existingFileName, false);
}
public static JFileChooser promptToOpenFile(String[] exts, String existingFileName, boolean onlyDirectories) {
return promptToOpenFile(GuiPackage.getInstance().getMainFrame(), exts, existingFileName, onlyDirectories);
}
public static JFileChooser promptToOpenFile(Component parentComponent, String[] exts, String existingFileName, boolean onlyDirectories) {
if (onlyDirectories) {
jfc.setFileSelectionMode(1);
} else {
jfc.setFileSelectionMode(0);
}
setCurrentDirOnJFC(existingFileName, lastJFCDirectory, System.getProperty("user.dir"));
clearFileFilters();
if (exts != null && exts.length > 0) {
JMeterFileFilter currentFilter = new JMeterFileFilter(exts);
jfc.addChoosableFileFilter(currentFilter);
jfc.setAcceptAllFileFilterUsed(true);
jfc.setFileFilter(currentFilter);
}
int retVal = jfc.showOpenDialog(parentComponent);
lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
return retVal == 0 ? jfc : null;
}
private static void setCurrentDirOnJFC(String... dirNames) {
String[] var1 = dirNames;
int var2 = dirNames.length;
for(int var3 = 0; var3 < var2; ++var3) {
String dirName = var1[var3];
if (!StringUtils.isBlank(dirName)) {
File possibleDir = new File(dirName);
if (possibleDir.exists() && possibleDir.canRead()) {
jfc.setCurrentDirectory(possibleDir);
return;
}
}
}
LOG.info("No valid initial directory found for: {}", Arrays.asList(dirNames));
jfc.setCurrentDirectory((File)null);
}
private static void clearFileFilters() {
FileFilter[] filters = jfc.getChoosableFileFilters();
FileFilter[] var1 = filters;
int var2 = filters.length;
for(int var3 = 0; var3 < var2; ++var3) {
FileFilter filter = var1[var3];
jfc.removeChoosableFileFilter(filter);
}
}
public static JFileChooser promptToSaveFile(String filename) {
return promptToSaveFile(filename, (String[])null);
}
public static JFileChooser promptToSaveFile(String filename, String[] extensions) {
String ext;
if (lastJFCDirectory == null) {
ext = System.getProperty("user.dir", "");
if (ext.length() > 0) {
jfc = new JFileChooser(new File(ext));
}
lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
}
ext = ".jmx";
int retVal;
if (filename != null) {
jfc.setDialogTitle(filename);
jfc.setSelectedFile(filename.lastIndexOf(File.separator) > 0 ? new File(filename) : new File(lastJFCDirectory, filename));
int i = true;
if ((retVal = filename.lastIndexOf(46)) > -1) {
ext = filename.substring(retVal);
}
}
clearFileFilters();
if (extensions != null) {
jfc.addChoosableFileFilter(new JMeterFileFilter(extensions));
} else {
jfc.addChoosableFileFilter(new JMeterFileFilter(new String[]{ext}));
}
retVal = jfc.showSaveDialog(GuiPackage.getInstance().getMainFrame());
jfc.setDialogTitle((String)null);
lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
return retVal == 0 ? jfc : null;
}
public static String getLastJFCDirectory() {
return lastJFCDirectory;
}
public static void setLastJFCDirectory(String lastJFCDirectory) {
FileDialoger.lastJFCDirectory = lastJFCDirectory;
}
}
|