Jar not working?

374 views Asked by At

I've created an application (in Java) and make it password protected: when I run/compile my code in Eclipse it works fine but when I created a jar file and run that jar it was not working: it shows me the initial frame but nothing works after that:

Initially when I created first jar that one works fine but when I just add password reset capability it just stop working:

Before answer please keep in mind that code works fine in compiler (i.e Eclipse) but not working when converted into a jar.

Conversion procedure: File>Export>Runnable Jar (option chosen - package required libraries into jar)

Output that works in Eclipse - screen shot image here https://i.stack.imgur.com/eVigb.jpg

One that's not working (executed from jar) screen shot image here https://i.stack.imgur.com/9oDOA.jpg

Piece of code related (consider each and every thing declared and initialized)

public JFrame psFrame=new JFrame("Password Check");
    private JPasswordField psField;
        private static int  tries=5;
    static boolean condition=false;
    private String Check,password;


        //////////// CONSTRUCTOR  ///////////
public  MenusAndButtons(){
    super("Explorer");
    extraString=null;
    try {passwordSetter();}catch (FileNotFoundException e){e.printStackTrace();}
    paswardCheck();

}


public synchronized  void  paswardCheck(){


Check=null;
psFrame.setSize(400, 120);
psFrame.setLocation(480, 300);

psField=new JPasswordField("",30); 
psField.addActionListener(new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent e) {

        if(e.getSource()==psField){ 
            Check=e.getActionCommand();

    if(tries!=1){


                if(Check!=null){


                             if(password.equals(Check)){
                             JOptionPane.showMessageDialog(null, "Welcome to Explorer ", "Welcome", JOptionPane.INFORMATION_MESSAGE);
                             condition=true;
                             psFrame.dispose();
                             Mnb();}
                             else{tries--;
                             JOptionPane.showMessageDialog(null,"You Entered a Wrong Password.\nYou are Left With " +tries+ " more Tries.\nPlease complete The Password Check with Correct Password\n", "Warrnning ",JOptionPane.WARNING_MESSAGE);  
                             psField.setText(null); }


                }else{JOptionPane.showMessageDialog(null,"You Entered Nothing in Password Field.\nPlease Enter a Password.","Null value Password Check",JOptionPane.ERROR_MESSAGE); 
                psField.setText(null);}


    }else{JOptionPane.showMessageDialog(null,"You Entered a Wrong Password 5 Times.\nExplorer is Quiting Now.","Password Check Failed ",JOptionPane.ERROR_MESSAGE); 
    psFrame.dispose();
    System.exit(0);}


    }  

    }});
psFrame.setLayout(new FlowLayout());
psFrame.add(new JLabel("Enter Password"));
psFrame.add(psField);
psFrame.setResizable(false);
psFrame.setVisible(true);


}




public void passwordSetter() throws FileNotFoundException{

    Scanner sc=new Scanner(new File("PasswordContainer.txt"));
    while(sc.hasNext())
        password=sc.nextLine();
    sc.close();

}

public void passwordresetter() throws Exception{


    String old=JOptionPane.showInputDialog(null,"Please Enter current Password","Current Password Check",JOptionPane.CANCEL_OPTION);
    if(old.equals(password)){
    String usererntry=JOptionPane.showInputDialog(null, "Please Enter new Password","Reset Password",JOptionPane.CANCEL_OPTION);

    if(usererntry.length()>=6){
    Formatter fp=new Formatter("PasswordContainer.txt");
    fp.format("%s",usererntry);
    fp.close();
    JOptionPane.showMessageDialog(null,"You've successfully Change Your Password","Password Change Conformation",JOptionPane.PLAIN_MESSAGE);
}else{  
    JOptionPane.showMessageDialog(null,"You Password Must Contain at least 6 Characters\nPlease Retype the New Password ");
    passwordresetter();}
        }


    else{JOptionPane.showMessageDialog(null,"You Entered Wrong Password\nPlease Retype the Current Password ");
    passwordresetter();
  }    
}
1

There are 1 answers

0
AudioBubble On

From your description, it sounds like your jar is not assembling as you think it is.

If a panel isn't showing up then you're likely missing a supporting library.

I would open up with jar file and go through the contents. Its a fun exercise anyway when you're learning Java (I noticed you're a student by your profile). Go through the jar and make sure it contains everything it should to support your app. My guess is that whatever framework you're using didn't fully copy into your jar.