Java 小程序运行时异常:java.lang.NoClassDefFoundError:javax/mail/Authenticator

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7428660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:56:24  来源:igfitidea点击:

Java applet RuntimeException: java.lang.NoClassDefFoundError: javax/mail/Authenticator

appletjava

提问by k4b

I have written my first java applet and get errors when deploying it on my web server. My applet uses couple of additional jar files like javaMail mail.jar, smtp.jar, mailapi.jarand others. When I try to display my applet in web browser I get such info in Error Dialog:

我已经编写了我的第一个 Java 小程序,但在我的 Web 服务器上部署它时出现错误。我的小程序使用一些额外的jar文件一样的JavaMail mail.jarsmtp.jarmailapi.jar和其他人。当我尝试在网络浏览器中显示我的小程序时,我在错误对话框中得到了这样的信息:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/mail/Authenticator
..
Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator
    ... 20 more

I am not very good with web applications and not sure what causes this error. From the info I assume that my applet cannot load the libraries. So how can I solve this? I have those libraries on my server in /lib directory. All other files are in main directory. My HTML file is as follows:

我不太擅长 Web 应用程序,不确定是什么导致了这个错误。根据信息,我假设我的小程序无法加载库。那么我该如何解决这个问题呢?我的服务器上的 /lib 目录中有这些库。所有其他文件都在主目录中。我的 HTML 文件如下:

<HTML>
<HEAD>
   <TITLE>TPSA Speed Test</TITLE>
</HEAD>
<BODY>
<P>
<APPLET code="speedtester_pkg/AppletMain.class" archive="SpeedTester.jar" width=440     height=600></APPLET>
</P>
</BODY>
</HTML>

I also tried to load my applet to web browser using JNLP with the same effect. I tried to find some way to point those libraries in HTML file, but I didn't manage (tried to add another jararchive lines or nativelibin JNLP file). I also tried to add those libraries to jar file with my applet classes, but that didn't help either.

我还尝试使用 JNLP 将我的小程序加载到 Web 浏览器,效果相同。我试图找到某种方法在 HTML 文件中指向这些库,但我没有管理(尝试添加另一个jar存档行或nativelib在 JNLP 文件中)。我还尝试使用我的小程序类将这些库添加到 jar 文件中,但这也无济于事。

This is my code where I use javaMail (sendTestResults() method near end of the code):

这是我使用 javaMail 的代码(接近代码末尾的 sendTestResults() 方法):

/*
 * AppletMain.java
 */
package speedtester_pkg;

import java.awt.*;
import java.beans.*;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class AppletMain extends javax.swing.JApplet implements PropertyChangeListener{

private ArrayList<String> customerFields;
private DataReader dataReader;
private Test test;
private FileHandler fh;
private ProgressBarTask progressBarTask;
private JTextField[] customerData;
private String speed, cpuLoad, NICspeed, testTime;
private int timeDef = 60;
    /**
 * The input file directory
 */
//    public String directory = "C:\Documents and Settings\Administrator\Pulpit\";
public String filename = "speedtestData.txt";
/**
 * Input file should be  a simple "*.txt" file named "speedtestData.txt"
 */
public File file;
// mail sending data
/**
 * TO DO encrypt mailing data
 */
private String smtpHost = "smtp.gmail.com",
        username = "myUserName",
        password = "myPassword";

private int port = 465; // TLS 587/ SSL 465


/** Initializes the applet Applet */
@Override
public void init() {
    try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                createGUI();
            }
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

/** This method is called from within the init() method to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    infoPanel = new javax.swing.JPanel();
    labelLogo = new javax.swing.JLabel();
    labelTitle = new javax.swing.JLabel();
    labelLinkSpeed = new javax.swing.JLabel();
    labelProcessorLoad = new javax.swing.JLabel();
    labelNIC = new javax.swing.JLabel();
    buttonStart = new javax.swing.JButton();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jProgressBar = new javax.swing.JProgressBar();
    formPanel = new javax.swing.JPanel();
    jLabel8 = new javax.swing.JLabel();
    buttonSend = new javax.swing.JButton();
    labelForm = new javax.swing.JLabel();
    infoLabel = new javax.swing.JLabel();
    jScrollPane = new javax.swing.JScrollPane();
    commentText = new javax.swing.JTextArea();

    labelTitle.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    labelTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    labelTitle.setText("Link Speed Test");

    labelLinkSpeed.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
    labelLinkSpeed.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

    labelProcessorLoad.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
    labelProcessorLoad.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

    labelNIC.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    labelNIC.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

    buttonStart.setText("Start");
    buttonStart.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            buttonStartActionPerformed(evt);
        }
    });

    jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
    jLabel4.setText("Szybko?? ??cza:");

    jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
    jLabel5.setText("Obci??enie procesora:");

    jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
    jLabel6.setText("Szybko?? karty sieciowej:");

    javax.swing.GroupLayout infoPanelLayout = new javax.swing.GroupLayout(infoPanel);
    infoPanel.setLayout(infoPanelLayout);
    infoPanelLayout.setHorizontalGroup(
        infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoPanelLayout.createSequentialGroup()
            .addComponent(labelLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(infoPanelLayout.createSequentialGroup()
                    .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel5)
                        .addComponent(jLabel6)
                        .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(labelLinkSpeed, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                        .addComponent(labelProcessorLoad, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                        .addComponent(labelNIC, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)))
                .addComponent(labelTitle, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(22, 22, 22))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoPanelLayout.createSequentialGroup()
            .addContainerGap(352, Short.MAX_VALUE)
            .addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
    );
    infoPanelLayout.setVerticalGroup(
        infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(infoPanelLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoPanelLayout.createSequentialGroup()
                    .addComponent(labelTitle)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(labelLinkSpeed, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel5)
                        .addComponent(labelProcessorLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel6)
                        .addComponent(labelNIC, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(6, 6, 6))
                .addGroup(infoPanelLayout.createSequentialGroup()
                    .addGap(16, 16, 16)
                    .addComponent(labelLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
            .addComponent(buttonStart)
            .addContainerGap())
    );

    javax.swing.GroupLayout formPanelLayout = new javax.swing.GroupLayout(formPanel);
    formPanel.setLayout(formPanelLayout);
    formPanelLayout.setHorizontalGroup(
        formPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 417, Short.MAX_VALUE)
    );
    formPanelLayout.setVerticalGroup(
        formPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 127, Short.MAX_VALUE)
    );

    jLabel8.setText("Uwagi:");

    buttonSend.setText("Wy?lij");
    buttonSend.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            buttonSendActionPerformed(evt);
        }
    });

    labelForm.setFont(new java.awt.Font("Tahoma", 0, 14));
    labelForm.setText("Formularz:");

    infoLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
    infoLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    infoLabel.setText("Kliknij przycisk \"Start\" aby rozpocz?? test");

    commentText.setColumns(20);
    commentText.setRows(5);
    jScrollPane.setViewportView(commentText);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 437, Short.MAX_VALUE)
        .addGap(0, 437, Short.MAX_VALUE)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
                .addComponent(formPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(infoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
                .addComponent(infoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(labelForm)
                .addComponent(buttonSend, javax.swing.GroupLayout.Alignment.TRAILING))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 572, Short.MAX_VALUE)
        .addGap(0, 572, Short.MAX_VALUE)
        .addGroup(layout.createSequentialGroup()
            .addComponent(infoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(infoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(labelForm)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(formPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(buttonSend)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
}// </editor-fold>                        

public void createGUI()
{
    try {
        dataReader = new DataReader(this);
        dataReader.read();
        customerFields = dataReader.getCustomerFields();
        testTime = String.valueOf(dataReader.getTestTime());
        initComponents();
        generateCustomerForm();
        test = new Test(this, dataReader.getDownloadURLs(), dataReader.getTestTime());
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    }


}

private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {                                            
    buttonStart.setEnabled(false);
    infoLabel.setText("Poczekaj do końca testu...");
    progressBarTask = new ProgressBarTask(this);
            infoLabel.setText("progress bar");
    progressBarTask.addPropertyChangeListener(this);
    progressBarTask.execute();
    Thread testThread = new Thread(this.test);
    testThread.start();
    System.out.println("Test thread \"" + testThread.getName() + "\" started.");
}                                           

private void buttonSendActionPerformed(java.awt.event.ActionEvent evt) {                                           
    try {
        sendTestResults();
    } catch (MessagingException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(AppletMain.class.getName()).log(Level.SEVERE, null, ex);
    }

}                                          

private void generateCustomerForm() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
{
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    //correcting auto-generated layout
    jLabel8.setFont(new java.awt.Font("Tahoma", 0, 11));
    labelProcessorLoad.setAlignmentX(RIGHT_ALIGNMENT);
    labelLogo.setIcon(new ImageIcon(getImage(getDocumentBase(), "orange.jpeg")));

    //gereate JLabels and JTextFields read from file
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    formPanel.setLayout(gridBagLayout);
    customerData = new JTextField[customerFields.size()];

    for(int i=0; i<customerFields.size(); i++)
    {
        JLabel l = new JLabel(customerFields.get(i));
        l.setFont(new java.awt.Font("Tahoma", 0, 11));
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx=0;
        gbc.gridy=i;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        formPanel.add(l, gbc);

        JTextField t = new JTextField();
        t.setFont(new java.awt.Font("Tahoma", 0, 11));
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx=1;
        gbc.gridy=i;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        formPanel.add(t, gbc);
        customerData[i] = t;
    }

}

/**
 * Invoked when task's progress property changes.
 */
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals("progress")) {
        int progress = (Integer) evt.getNewValue();
        jProgressBar.setValue(progress);
    }
}

public void setLabelProcessorLoad(String text)
{
    labelProcessorLoad.setText(text);
}

public void setLabelLinkSpeed(String text)
{
    labelLinkSpeed.setText(text);
}

public void setLabelNIC(String text)
{
    labelNIC.setText(text);
}

public JProgressBar getProgressBar()
{
    return jProgressBar;
}

public JButton getButtonStart()
{
    return buttonStart;
}

public Test getTest()
{
    return this.test;
}

public void setNICspeed(String NICspeed) {
    this.NICspeed = NICspeed;
}

public void setCpuLoad(String cpuLoad) {
    this.cpuLoad = cpuLoad;
}

public void setSpeed(String speed) {
    this.speed = speed;
}

public JLabel getInfoLabel() {
    return infoLabel;
}
/**
 * Prepares e-mail message for sending via google SMTP protocol with SSL
 */
private void sendTestResults() throws MessagingException, UnsupportedEncodingException{
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(props,
    new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username,password);
        }
    });

    MimeMessage message = new MimeMessage(session);
    //Setting message fields
    Address toAddress = new InternetAddress(dataReader.getMail(), "SpeedTest crew");
    message.addRecipient(Message.RecipientType.TO, toAddress);
    message.setSubject("SpeedTest");

    message.setText(prepareMailText(), "UTF8");

    Transport.send(message);
    infoLabel.setText("Wiadomo?? z wynikami testu zosta?a wys?ana pomy?lnie");
    System.out.println("Mail sent.");
}

/**
 * Gets all test results and customer data and prepares mail content
 * @return the content of e-mail body
 */
private String prepareMailText()
{
    String messageContentHeader = "Pr?dko?? pobierania\t" + "Obci??enie procesora\t" +
            "Szybko?? ??cza karty sieciowej\t" + "Czas trwania testu\t";
    String messageContent = speed + "\t"+ cpuLoad + "\t" + NICspeed + "\t" + testTime + "\t";

    for(int j=0;j<customerData.length;j++)
    {
        messageContentHeader += customerFields.get(j) + "\t";
        messageContent += customerData[j].getText() + "\t";
    }
    messageContentHeader += "Uwagi";
    messageContent += commentText.getText();
    String messageText = messageContentHeader + "\n" + messageContent;
    return messageText;
}

// Variables declaration - do not modify                     
private javax.swing.JButton buttonSend;
private javax.swing.JButton buttonStart;
private javax.swing.JTextArea commentText;
private javax.swing.JPanel formPanel;
private javax.swing.JLabel infoLabel;
private javax.swing.JPanel infoPanel;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel8;
private javax.swing.JProgressBar jProgressBar;
private javax.swing.JScrollPane jScrollPane;
private javax.swing.JLabel labelForm;
private javax.swing.JLabel labelLinkSpeed;
private javax.swing.JLabel labelLogo;
private javax.swing.JLabel labelNIC;
private javax.swing.JLabel labelProcessorLoad;
private javax.swing.JLabel labelTitle;
// End of variables declaration                   



}

I also had a problem with other libraries like Sigar.jar, but I suppose it will solve similarly.

我也遇到了像 Sigar.jar 这样的其他库的问题,但我想它会以类似的方式解决。

Somebody has good tips?

有人有好的建议吗?

回答by Andrew Thompson

It is necessary to add the Jar containing the javax.mailpackages to the run-time class-path of the applet. To achieve that (one way is to) put that Jar in the same place SpeedTester.jarand change the archive attribute from:

有必要将包含javax.mail包的 Jar 添加到小程序的运行时类路径。为了实现这一点(一种方法是)将该 Jar 放在同一个地方,SpeedTester.jar并从以下位置更改存档属性:

archive="SpeedTester.jar"

..to:

..到:

archive="SpeedTester.jar,mail.jar"

Update 1

更新 1

Change the entire applet element:

更改整个小程序元素:

From

<APPLET 
    code="speedtester_pkg/AppletMain.class" 
    archive="SpeedTester.jar" 
    width=440     
    height=600>
</APPLET>

To

<APPLET 
    code="speedtester_pkg.AppletMain" 
    archive="SpeedTester.jar,mail.jar" 
    width=440     
    height=600>
</APPLET>

Presuming the package of the applet class is speedtester_pkgand the applet is named AppletMain. The code attribute should be the fully qualified name of the applet class, not the path/file name.

假设小程序类的包为 ,小speedtester_pkg程序名为AppletMain。代码属性应该是小程序类的完全限定名,而不是路径/文件名。

Update 2

更新 2

The above advice re. the mail.jardoes not account for classes that are referenced from within the Test, DataReaderor ProgressBarTask(or the classes they load). 'Rinse and repeat' that advice for adding extra APIs to the run-time class-path using the archive attribute.

以上建议重新。在mail.jar不考虑被从内部被引用类TestDataReader或者ProgressBarTask(或者它们的类加载)。“冲洗并重复”使用存档属性向运行时类路径添加额外 API 的建议。

Note

笔记

It seems the other answers are referring to a web-app. that is entirely server-side. For such a web-app., putting Jars into the libmakes sense. OTOH an applet can only access a Jar that is available by copy/pasting the URL of the Jar into the browser address bar and hitting enter.

其他答案似乎是指网络应用程序。那完全是服务器端的。对于这样的网络应用程序,将 Jars 放入其中lib是有意义的。OTOH 小程序只能通过将 Jar 的 URL 复制/粘贴到浏览器地址栏中并点击 来访问可用的 Jar enter

In fact doing just that, using a combination of the code-base & href of the Jar, is a good 'acid test' of whether an applet will be able to access the archive.

实际上这样做,使用 Jar 的代码库和 href 的组合,是一个很好的“酸性测试”,以确定小程序是否能够访问档案。

回答by duffymo

Looks like you're missing the JAR with javax.mail.Authenticator

看起来你错过了 JAR javax.mail.Authenticator

You can use the FindJar site to figure out what the name of the JAR is and where to download it. Google for it; it's worth knowing about.

您可以使用 FindJar 站点来确定 JAR 的名称以及在哪里下载它。谷歌一下;值得了解。

You might be missing others as well. Keep adding JARs to your app's WEB-INF/lib until those CNF exceptions go away.

你也可能会想念其他人。继续向应用程序的 WEB-INF/lib 添加 JAR,直到这些 CNF 异常消失。

回答by Saket

Missing JARs (mail.jar in your case) is the primary reason for any ClassNotFound exception. Place it in your app server's libdirectory to resolve this.

缺少 JAR(在您的情况下为 mail.jar)是任何 ClassNotFound 异常的主要原因。将其放在应用服务器的lib目录中以解决此问题。