14 Replies Latest reply on Aug 4, 2006 1:08 AM by 796254

    ******PLEASE HELP********

    807569
      Hello,

      Trying to create executable jar but have not been very successful. Basically have created a database table which includes jdbc driver library. During execution of command line it throws a FileNotFoundException for a jar file which I am trying to create. Can someone tell me what's wrong.

      Thanks
        • 1. Re: ******PLEASE HELP********
          807569
          Can someone tell me what's wrong.
          it throws a FileNotFoundException for a jar file which I am trying to create.
          • 2. Re: ******PLEASE HELP********
            807569
            Hello IanSchneider,

            should it complain for a new archive which is going to be just created on the fly?

            Thanks
            • 3. Re: ******PLEASE HELP********
              DrClap
              FileNotFoundException is pretty self-explanatory. It means the system can't find a file you asked it to find. And that would be because the file doesn't exist. Saying "But I'm just about to create it!" isn't good enough.
              • 4. Re: ******PLEASE HELP********
                807569
                Hello DrClap,

                How can it find an archive when it is trying to create it! Example trying to create a new archive called myapp.jar by executing jar command line. It throws a FileNotFoundException for myapp.jar. How can this be. "myapp.jar" is the very archive to being created! It is not complaining for files missing to put in the jar archive but it is complaining for the jar archive itself.

                Thanks
                • 5. Re: ******PLEASE HELP********
                  807569
                  Post the actual error message and the actual code that's causing the error message.
                  • 6. Re: ******PLEASE HELP********
                    807569
                    Hello Paulcw,

                    The error code as requested>

                    java.io.FileNotFoundException: myapp.jar (The system cannot find the file specified)
                    at java.io.FileInputStream.open(Native Method)
                    at java.io.FileInputStream.<init>(FileInputStream.java:106)
                    etc........

                    Thanks
                    • 7. Re: ******PLEASE HELP********
                      807569
                      OK, now post your code. Also, post more of the stack trace. We want to see enough of the stack trace that we can see the methods that you wrote listed.
                      • 8. Re: ******PLEASE HELP********
                        807569
                        Hello paulcw

                        Source code for TestApp.java>
                        import java.awt.Dimension;
                        import java.awt.EventQueue;
                        import java.awt.Toolkit;
                        import java.sql.Connection;
                        import java.sql.DriverManager;
                        import java.sql.PreparedStatement;
                        import java.sql.ResultSet;
                        import java.sql.SQLException;
                         
                        import javax.swing.JFrame;
                        import javax.swing.JScrollPane;
                        import javax.swing.JTable;
                        import javax.swing.table.AbstractTableModel;
                         
                         
                        public class TestTable implements Runnable {
                             
                             private Toolkit toolkit = Toolkit.getDefaultToolkit();
                             private Dimension screenSize = toolkit.getScreenSize();
                             
                             public static void main(String[] args) {
                                  Runnable r = new TestTable();
                                  EventQueue.invokeLater(r);
                             }
                             
                             public void run() {
                                  try {
                                       init();
                                  }catch(Exception ex){
                                       ex.printStackTrace();
                                  }
                             }
                             
                             private void init() throws Exception{
                                  JTable table = new JTable(new TableValues("select * from contact"));
                                  JScrollPane scroller = new JScrollPane(table);
                             
                                  JFrame frame = new JFrame("My Database");
                                  frame.getContentPane().add(scroller);
                                  frame.setResizable(false);
                                  frame.setSize(screenSize);
                                  frame.setVisible(true);
                                  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                             }
                             
                             private class TableValues extends AbstractTableModel {
                                  private Connection con;
                                  private PreparedStatement pstmt;
                                  private ResultSet rs;
                                  
                                  public TableValues(String query){
                                       try {
                                            init(query);
                                       }catch(Exception ex) {
                                            ex.printStackTrace();
                                       }
                                  }
                                  
                                  private synchronized void init(String query) throws Exception {
                                       con = getConnection();
                                       pstmt = con.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, 
                                                 ResultSet.CONCUR_UPDATABLE);
                                       rs = pstmt.executeQuery();
                                       
                                  }
                                  
                                  public int getRowCount() {
                                       try {
                                            if(rs != null) {
                                                 rs.last();
                                                 return rs.getRow();
                                            }
                                       }
                                       catch(SQLException sqlex) {
                                            System.err.println("Error: " + sqlex.getMessage());
                                       }
                                       
                                       return 0;
                                  }
                                  
                                  public int getColumnCount() {
                                       try{
                                            if(rs != null) {
                                                 return rs.getMetaData().getColumnCount();
                                            }
                                       }
                                       catch(SQLException sqlex) {
                                            System.err.println("Error: " + sqlex.getMessage());
                                       }
                         
                                       return 0;
                                  }
                                  
                                  public Object getValueAt(int row, int column) {
                                       try {
                                            if(rs != null) {
                                                 if(rs.absolute(row+1)) {
                                                      return rs.getString(column + 1);
                                                 }
                                            }
                                       }
                                       catch(SQLException sqlex) {
                                            System.err.println("Error: " + sqlex.getMessage());
                                       }
                                       
                                       return null;
                                  }
                                  
                                  public String getColumnName(int column) {
                                       try {
                                            if(rs != null) {
                                                 return rs.getMetaData().getColumnName(column+1);
                                            }
                                       }
                                       catch(SQLException sqlex) {
                                            System.err.println("Error: " + sqlex.getMessage());
                                       }
                                       return null;
                                  }
                                  
                                  private synchronized Connection getConnection() throws ClassNotFoundException,
                                      SQLException {
                                    final String __DRIVER__ = "org.postgresql.Driver";
                                    final String __URL__ = "jdbc:postgresql://192.169.0.6:5432/mydb";
                                    final String __USERNAME__ = "super";
                                    final String __PASSWORD__ = "man";
                                  
                                    Class.forName(__DRIVER__);
                                  
                                    return DriverManager.getConnection(__URL__, __USERNAME__, __PASSWORD__);
                                  }
                                  
                             }
                        }
                        Manifest file TestApp.mf >
                        Manifest-Version: 1.0
                        Main-Class: TestApp
                        Created-By: 1.6 (Sun Microsystems Inc.)
                        Remainder of the stacktrace >
                        at java.io. FileInputStream. <init>(FileInputStream.java 66)
                        at sun.tools.jar.Main.run(Main.java:123)
                        at sun.tools.jar.Main.main(Main.java:960)
                        Thanks
                        • 9. Re: ******PLEASE HELP********
                          807569
                          Wait this code has nothing to do with jar. I thought you meant you were trying to Runtime.exec it.

                          How are you invoking jar from the command line?
                          • 10. Re: ******PLEASE HELP********
                            DrClap
                            Reading between the lines: it's probably something stupid like the manifest says it's part of the jar's classpath but the code is trying to create it.
                            • 11. Re: ******PLEASE HELP********
                              807569
                              Hello paulcw,

                              Sorry misunderstood :-(. Here it is >

                              jar -cvmf TestApp.jar TestApp.mf -C classes/ *

                              Thanks
                              • 12. Re: ******PLEASE HELP********
                                807569
                                Hello paulcw

                                May have worked it out. My command line shoud have been >

                                jar -cvmf TestApp.mf TestApp.jar *

                                Thanks
                                • 13. Re: ******PLEASE HELP********
                                  807569
                                  Hello paulcw,

                                  Have successfully created an executable jar file.

                                  Thanks
                                  • 14. Re: ******PLEASE HELP********
                                    796254
                                    you have to have the 3rd party JARs in the CLASSPATH relative to the executable JAR. There's a CLASSPATH in the manifest that tells the JVM where to look for them. The easiest thing to do is to put the 3rd party JARs in the same directory as yours and list their names in the manifest CLASSPATH.

                                    %