Reputation: 91
I'm trying to run a program I've made in eclipse. Have exported it as a runnable jar file, and saved it on the desktop, but when I try to run it from the command prompt it says : "Error: Unable to access jarfile Matador.jar"
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Password implements ActionListener {
private String Username = "hudhud";
private String Password = "fitness";
private JTextField txtUsername;
private JTextField txtPassword;
public static void main(String[] args){
Password gui = new Password();
gui.go();
}
public void go(){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JLabel lblUsername = new JLabel("Username:");
JLabel lblPassword = new JLabel("Password:");
txtUsername = new JTextField(20);
txtPassword = new JTextField(20);
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(this);
JButton btnCancel = new JButton("Cancel");
btnCancel.addActionListener(this);
panel.add(lblUsername);
panel.add(txtUsername);
panel.add(lblPassword);
panel.add(txtPassword);
panel.add(btnLogin);
panel.add(btnCancel);
frame.getContentPane().add(BorderLayout.CENTER,panel);
frame.setSize(300,300);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
String msg;
if (cmd.equals("Login")) {
if (txtUsername.getText().equals(Username) && txtPassword.getText().equals(Password)) {
msg = "Welcome";
} else {
msg = "Login denied. The username or password is incorrect";
}
} else {
msg = "Where are you going, couldn't you guess the password and username??";
}
JOptionPane.showMessageDialog(null, msg);
}
}
Upvotes: 0
Views: 1709
Reputation: 1719
Project structure:
c:\project\Matador.jar
cd c:\project
java -jar Matador.jar
Upvotes: 0
Reputation: 22343
That error means, that the jar file couldn't be found. You have to specify the path to your jar like that:
java -jar path/To/Your/Jar/Matador.jar
Upvotes: 0
Reputation: 356
Do this:
java -jar <jar-file-name>.jar
Just make sure you are in the right directory.
Duplicate question: Run jar file in command prompt
Upvotes: 1