I have a java program with common-net library. It works fine in windows when i run it from eclipse. But when i try to run the file from Unix it doesn't seem to like the FTPClient class that i imported from java common-net library. My library's are in jar file that i added to my sourceBuild path when i included in the project. Here is my code:
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.text.ParseException;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.text.MaskFormatter;
import org.apache.commons.net.ftp.FTPClient;
public class ReTransmitToVendor {
public static void main (String []args)
{
Runnable runner = new Runnable()
{
public void run()
{
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
}
JFrame frame = new JFrame("Ftp Re-Transmit");
frame.setSize(800, 420);
frame.setVisible(true);
frame.setLocation(200, 200);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu programMenu = new JMenu("Program");
menuBar.add(programMenu);
final JMenuItem exitItem = new JMenuItem("Exit", new ImageIcon ("exit.png"));
programMenu.add(exitItem);
JMenu helpMenu = new JMenu("Help");
menuBar.add(new JPanel());
menuBar.add(helpMenu);
final JMenuItem aboutItem = new JMenuItem("About", new ImageIcon("about.png"));
helpMenu.add(aboutItem);
JPanel topPanel = new JPanel(new BorderLayout());
frame.add(topPanel, BorderLayout.NORTH);
JPanel titlePanel = new JPanel(new FlowLayout());
topPanel.add(titlePanel);
JLabel titleLabel = new JLabel("Ftp-Retransmit To Vendor");
titleLabel.setFont(new Font (null, Font.BOLD, 14));
titleLabel.setForeground(Color.BLUE);
titlePanel.add(titleLabel);
JPanel gridPanel = new JPanel(new GridLayout(2, 2));
frame.add(gridPanel);
JPanel comboBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
gridPanel.add(comboBoxPanel);
String [] vendors = {"68.98.136.5:21"};
JComboBox vendorComboBox = new JComboBox(vendors);
comboBoxPanel.add(vendorComboBox);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
gridPanel.add(buttonPanel);
final JButton transmitButton = new JButton("Re-Transmit");
buttonPanel.add(transmitButton);
JPanel filePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
gridPanel.add(filePanel);
JLabel fileLabel = new JLabel("File: ");
fileLabel.setFont(new Font(null, Font.BOLD, 12));
filePanel.add(fileLabel);
final JTextField fileNameField = new JTextField(30);
fileNameField.setEditable(false);
filePanel.add(fileNameField);
JPanel browsePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
gridPanel.add(browsePanel);
final JButton browseButton = new JButton("Browse");
browseButton.setMargin(new Insets(0,12,0,12));
browsePanel.add(browseButton);
ActionListener menuItemListener = new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource()== exitItem)
{
JOptionPane.showMessageDialog(null, "You're Program is about exit!");
System.exit(0);
}
else if (ae.getSource() == aboutItem)
{
JOptionPane.showMessageDialog(null, "This software was created to Re-transmit to vendor");
}
}
};
exitItem.addActionListener(menuItemListener);
aboutItem.addActionListener(menuItemListener);
ActionListener browseListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == browseButton)
{
final JFileChooser fileChooser = new JFileChooser();
int showFileChooser = fileChooser.showOpenDialog(null);
File getFile = fileChooser.getSelectedFile();
if (showFileChooser == fileChooser.APPROVE_OPTION)
{
fileNameField.setText(getFile.getAbsolutePath());
}
}
}
};
browseButton.addActionListener(browseListener);
ActionListener transmitButtonListener = new ActionListener ()
{
public void actionPerformed(ActionEvent tbl)
{
if (tbl.getSource()== transmitButton)
{
String getDirectory = fileNameField.getText();
FTPClient client = new FTPClient();
try
{
client.connect("pearl.bna.com");
client.login("####", "######");
System.out.println(client.getReplyString());
File saveFile = new File (getDirectory);
FileInputStream fis = new FileInputStream(saveFile);
client.storeFile(saveFile.getName().toString(), fis);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
};
transmitButton.addActionListener(transmitButtonLis tener);
}
};
EventQueue.invokeLater(runner);
}
}