Merge external jar
<p>I have created simple Mail send java project in Netbeans IDE. I added an external jar <strong>javax.mail.jar</strong> in lib folder.I want to merge Multiple Jars into a Single Jar but <strong>javax.mail.jar</strong> did not merged. Please help me how <strong>javax.mail.jar</strong> can be merged</p>

<p>Source code:</p>

<pre><code>package nrb.vanggi;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Properties;
 import java.util.concurrent.ThreadLocalRandom;
 import javax.mail.BodyPart;
 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.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Example extends JFrame {
Session session = null;

public Example() {
    initUI();
}

public final void initUI() {

    JPanel panel = new JPanel();
    getContentPane().add(panel);

    panel.setLayout(null);

    JButton send = new JButton("Send");
    send.setBounds(50, 60, 80, 30);
    send.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            startingMailSend();

            emailSending();

        }
    });

    panel.add(send);

    setSize(300, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

private void startingMailSend() {

    //1) get the session object     
    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", "");
    properties.put("mail.smtp.auth", "true");

    //properties.put("mail.smtp.port", "465");
    //properties.put("mail.smtp.ssl.enable", "true");
    session = Session.getDefaultInstance(properties,
            new javax.mail.Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("rahim@duttafashion.info", "**********");
                }
            });

}

private void emailSending() {

    try {
        System.err.println("call");
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss dd, MMM");

        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("UserName" + "&lt;" + "rahim@duttafashion.info" + "&gt;"));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress("vanggibd@gmail.com"));
        message.setSubject(ThreadLocalRandom.current().nextLong(5000, 10000) + " " + "This is Subject");

        MimeMultipart multipart = new MimeMultipart("related");
        BodyPart messageBodyPart1 = new MimeBodyPart();
        messageBodyPart1.setContent(df.format(cal.getTime()) + "" + "Body area How are all????", "text/html");
        multipart.addBodyPart(messageBodyPart1);

        message.setContent(multipart);
        Transport.send(message);
        System.out.println("message sent....");
        JOptionPane.showMessageDialog(null, "Mail send success");
    } catch (MessagingException ex) {
        JOptionPane.showMessageDialog(null, ex);
        ex.printStackTrace();
        System.out.println("error");
    } catch (Exception ee) {
        System.err.println(" errorrrr" + ee);
    } finally {
        System.err.println("finally call");
    }

}

public static void main(String[] args) {

    Example ex = new Example();
    ex.setVisible(true);

}
</code></pre>

<p>}</p>

<pre><code>Sample build.xml configure:
&lt;target name="-post-jar"&gt;
     &lt;jar jarfile="dist/MailSend.jar"&gt;
      &lt;zipfileset src="${dist.jar}" excludes="META-INF/*" /&gt;   
     &lt;zipfileset src="lib/javax.mail.jar" excludes="META-INF/*"/&gt;
     &lt;manifest&gt;
         &lt;attribute name="Main-Class" value="nrb.vanggi.Example"/&gt;
     &lt;/manifest&gt;
     &lt;/jar&gt;
    &lt;/target&gt;
</code></pre>