Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java NoClassDefFoundError当我通过commnad线调用该类时_Java_Eclipse_Noclassdeffounderror_Javax.mail.address - Fatal编程技术网

Java NoClassDefFoundError当我通过commnad线调用该类时

Java NoClassDefFoundError当我通过commnad线调用该类时,java,eclipse,noclassdeffounderror,javax.mail.address,Java,Eclipse,Noclassdeffounderror,Javax.mail.address,我正在编写一个发送电子邮件的简单类,因此需要外部jar。我所做的是在eclipse项目中添加了外部JAR。它正在工作 但是当我从命令行调用该类时,它给出了NoClassDefFoundError:javax.mail.Address。这里有两件事,我复制了Javalib文件夹中的所有JAR,第二件事是javax.mail.Address在代码中没有直接引用。知道是什么问题或如何解决 该类有一个主函数,在没有电子邮件代码的情况下运行良好 p、 导入java.io.File; 导入java.io

我正在编写一个发送电子邮件的简单类,因此需要外部jar。我所做的是在eclipse项目中添加了外部JAR。它正在工作

但是当我从命令行调用该类时,它给出了NoClassDefFoundError:javax.mail.Address。这里有两件事,我复制了Javalib文件夹中的所有JAR,第二件事是javax.mail.Address在代码中没有直接引用。知道是什么问题或如何解决

该类有一个主函数,在没有电子邮件代码的情况下运行良好


p、

导入java.io.File;
导入java.io.FileInputStream;
导入java.io.IOException;
导入java.sql.Connection;
导入java.sql.DriverManager;
导入java.sql.ResultSet;
导入java.sql.SQLException;
导入java.sql.Statement;
导入java.util.Enumeration;
导入java.util.Properties;
导入javax.mail.Message;
导入javax.mail.MessaginException;
导入javax.mail.Session;
导入javax.mail.Transport;
导入javax.mail.internet.InternetAddress;
导入javax.mail.internet.mimessage;
公共类电子邮件通知{
受保护的静态字符串消息\u loseEvent;
受保护的静态特性;
受保护的静态连接;
受保护的静态会话;
公共静态void main(字符串[]args)引发异常
{
loadPropertiesFromXML(“applicationSettings.xml”);
setupMailServer();
_openDBConnection();
结果集R=_executeQuery(getQuery(“TodaysLossEventQuery”);
while(R.next()){
message_loseEvent=“namescriptionurl”+R.getString(R.findColumn(“Name”))+“”+R.getString(R.findColumn(“Description”)+“”;
}
电邮(“openpages@fvb.com“,”主题“,”内容“);
connection.close();
}
受保护的静态属性loadPropertiesFromXML(字符串文件路径)
{
尝试
{
文件文件=新文件(文件路径);
FileInputStream fileInput=新的FileInputStream(文件);
属性=新属性();
loadFromXML(fileInput);
fileInput.close();
归还财产;
}捕获(例外e)
{
e、 printStackTrace();
}
返回null;
}
受保护的静态字符串\u getProperty(字符串键)
{
枚举enuKeys=properties.keys();
while(enuKeys.hasMoreElements()){
字符串_key=(字符串)enuKeys.nextElement();
如果(_key.equals(key))
{
//System.out.println(“_getProperty()>”+properties.getProperty(key));
返回properties.getProperty(键);
}       
}
返回null;
}
受保护的静态void_openDBConnection()
抛出ClassNotFoundException、SQLException、IOException
{
//在职司机
Class.forName(“COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver”);
//forName(“com.ibm.db2.jcc.DB2Driver”);
字符串db_host=_getProperty(“db_host”);
字符串db_port=_getProperty(“db_port”);
字符串db_name=_getProperty(“db_name”);
字符串db_user=_getProperty(“db_用户名”);
字符串db_password=_getProperty(“db_password”);
connection=DriverManager.getConnection(“jdbc:db2://”+db_主机+:“+db_端口+”/“+db_名称、db_用户、db_密码);
//System.out.println(“>获得数据库连接”);
}
受保护的静态字符串getQuery(字符串queryTitle)
{
返回_getProperty(queryTitle);
}
//选择OPAGES.RT_LossEvent.LossEvent_ID作为losseventi,选择OPAGES.RT_LossEvent.NAME00作为Name,选择OPAGES.RT_LossEvent.DESCRIPTION作为DESCRIPTION,选择OPAGES.ACTORINFO.EMAIL作为EmailAddress,选择OPAGES.RT_LossEvent.DETAIL作为详细URL作为OPAGES.RT_LossEvent加入OPAGES.ACTORINFO上的详细URL(OPAGES.ACTORINFO.Name=OPAGES.RT_LossEvent.OWNER和CONCAT(年(当前日期),“-”,月(当前日期),月(当前日期))=CONCAT(年(OPAGES.RT_LossEvent.Creation_date),“-”,月(OPAGES.RT_LossEvent.Creation_date),月(OPAGES.RT_LossEvent.Creation_date),月(OPAGES.RT_LossEvent.Creation_date),“-”,日(OPAGES.RT_LossEvent.Creation_date);)
//结果集R
受保护的静态结果集\u executeQuery(字符串\u查询)
抛出ClassNotFoundException、SQLException、IOException{
//System.out.println(_查询);
语句s=connection.createStatement();
返回s.executeQuery(\u查询);
//while(R.next()){
//message_loseEvent=“namescriptionurl”+R.getString(R.findColumn(“Name”))+“”+R.getString(R.findColumn(“Description”)+“”;
//}       
}
受保护的静态void setupMailServer()
{
//需要提及收件人的电子邮件ID。
字符串to=_getProperty(“from_address”);
//需要提及发件人的电子邮件ID
字符串from=_getProperty(“from_address”);
//假设您正在从本地主机发送电子邮件
字符串主机=_getProperty(“电子邮件主机”);
//获取系统属性
Properties=System.getProperties();
//安装邮件服务器
setProperty(_getProperty(“电子邮件服务器”),主机);
//获取默认会话对象。
session=session.getDefaultInstance(属性);
}
受保护的静态无效电子邮件(字符串地址、字符串主题、字符串内容)
{
尝试
{
//创建默认的mimessage对象。
MimeMessage message=新MimeMessage(会话);
//设置自:标题的标题字段。
message.setFrom(新的InternetAddress(_getProperty(“from_address”));
//设置为:标题的标题字段。
message.addRecipient(message.RecipientType.TO,新的InternetAddress(_-toAddress));
//设置主题:标题字段
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailNotifications {

    protected static String     message_loseEvent ;
    protected static Properties properties;
    protected static Connection connection;
    protected static Session    session;

    public static void main(String [] args)throws Exception
    {
        loadPropertiesFromXML("applicatiosnSettings.xml");
        setupMailServer();
        _openDBConnection();

        ResultSet R = _executeQuery( getQuery("TodaysLossEventQuery")  );
        while(R.next()) {
                    message_loseEvent = "<table border=1 ><tr><td>Name</td><td>Description</td><td>URL</td></tr><tr><td>" + R.getString( R.findColumn("Name") ) + "</td><td>" + R.getString( R.findColumn("Description") ) + "</td><td><a href='" + R.getString( R.findColumn("DetailURL") ) + "'>See on OpenPages</a></td></tr></table>"; 
                }
        Email("openpages@fvb.com","subject","content");
        connection.close();
    }

    protected static Properties loadPropertiesFromXML(String filePath)
    {
        try
        {
            File file = new File(filePath);
            FileInputStream fileInput = new FileInputStream(file);
            properties = new Properties();
            properties.loadFromXML(fileInput);
            fileInput.close();
            return properties;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    protected static String _getProperty(String key)
    {
        Enumeration enuKeys = properties.keys();        

        while (enuKeys.hasMoreElements()) {
            String _key = (String) enuKeys.nextElement();
            if(_key.equals(key))
            {
                // System.out.println( " _getProperty() > " + properties.getProperty(key));
                return properties.getProperty(key);
            }       
        }

        return null;        
    }

    protected static void  _openDBConnection() 
            throws ClassNotFoundException, SQLException, IOException
    {
        //working Drivers
        Class.forName ( "COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver"  );
        //Class. forName ( "com.ibm.db2.jcc.DB2Driver"  );

        String db_host      = _getProperty("db_host");
        String db_port      = _getProperty("db_port");
        String db_name      = _getProperty("db_name");
        String db_user      = _getProperty("db_username");
        String db_password  = _getProperty("db_password");
        connection = DriverManager.getConnection("jdbc:db2://"+db_host+":"+db_port+"/"+db_name,db_user,db_password); 
        //System.out.println( "> DataBase connection obtained " );


    }

    protected static String getQuery(String queryTitle)
    {
        return _getProperty(queryTitle);        
    }

    //SELECT OPAGES.RT_LossEvent.LOSSEVENT_ID as LossEventId,OPAGES.RT_LossEvent.NAME00 as Name,OPAGES.RT_LossEvent.DESCRIPTION as Description,OPAGES.ACTORINFO.EMAIL as EmailAddress, OPAGES.RT_LossEvent.DETAIL_PAGE_URL as DetailURL FROM OPAGES.RT_LossEvent JOIN OPAGES.ACTORINFO ON (OPAGES.ACTORINFO.NAME = OPAGES.RT_LossEvent.OWNER AND CONCAT(CONCAT(Year(current date),'-'),CONCAT(Month(current date),CONCAT('-',Day(current date)))) = CONCAT(CONCAT(Year(OPAGES.RT_LossEvent.Creation_Date),'-'),CONCAT(Month(OPAGES.RT_LossEvent.Creation_Date),CONCAT('-',Day(OPAGES.RT_LossEvent.Creation_Date)))))
    //ResultSet R
    protected static ResultSet _executeQuery(String _query) 
            throws ClassNotFoundException, SQLException, IOException {  
        //System.out.println(_query);
        Statement s = connection.createStatement();
        return s.executeQuery(_query);
        //while(R.next()) {

        //  message_loseEvent = "<table border=1 ><tr><td>Name</td><td>Description</td><td>URL</td></tr><tr><td>" + R.getString( R.findColumn("Name") ) + "</td><td>" + R.getString( R.findColumn("Description") ) + "</td><td><a href='" + R.getString( R.findColumn("DetailURL") ) + "'>See on OpenPages</a></td></tr></table>"; 
        //}       
    }

    protected static void setupMailServer()
    {
          // Recipient's email ID needs to be mentioned.
          String to = _getProperty("from_address");
          // Sender's email ID needs to be mentioned
          String from = _getProperty("from_address");
          // Assuming you are sending email from localhost
          String host = _getProperty("email_host");

          // Get system properties
          Properties properties = System.getProperties();
          // Setup mail server
          properties.setProperty( _getProperty("email_server") , host);

          // Get the default Session object.
          session = Session.getDefaultInstance(properties);


    }

    protected static void Email(String _toAddress,String _subject,String _content)
    {
        try
        {
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);

            // Set From: header field of the header.
            message.setFrom(new InternetAddress( _getProperty("from_address") ));
            // Set To: header field of the header.
            message.addRecipient(Message.RecipientType.TO,new InternetAddress(_toAddress));
            // Set Subject: header field
            message.setSubject(_subject);
            // Send the actual HTML message, as big as you like
            message.setContent(message_loseEvent,"text/html" );

            // Send message
            Transport.send(message);
            //System.out.println("> Sent message successfully");
        }catch (MessagingException mex) 
        {
            mex.printStackTrace();
        }
    }

}
javac -cp <path to jar file> package/javafile.java
javac package/javafile.java 
java -cp "/path/to/lib/*:/other/paths/" ...
java -cp "/path/to/lib/*:/other/paths/:/path/to/main/class" ...