Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    .Jar not working after export in Eclipse

    I'm new to java and I'm trying to connect to a Postgresql database. When I run my program in Eclipse itself it works but when I export it (to build a .jar) I get an exception.

    java.lang.ClassNotFoundException: org.postgresql.Driver

    The .classpath is created by Eclipse and contains

    <classpathentry kind="lib" path="C:/Server/develop/resources/postgresql-8.4-702.jdbc4.jar"/>

    The path is correct, when I copy and past it in my file browser I get the file.

    Code:
    import java.sql.*;
    
    
    public class Main {
    	public static void main(String[] args) { 
    		
        	String url = "jdbc:postgresql://localhost/WorldCraft?user=postgres&password=sloeber007";
        	
        	try {
        		try {
    				Class.forName("org.postgresql.Driver");
    			} catch (ClassNotFoundException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			Connection conn = DriverManager.getConnection(url);
    			conn.close();
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    }

  • #2
    New Coder
    Join Date
    Feb 2011
    Posts
    48
    Thanks
    1
    Thanked 2 Times in 2 Posts
    If you link your library correctly, there shouldn't be errors.

    Here you can read more.

  • #3
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DistantJob View Post
    If you link your library correctly, there shouldn't be errors.

    Here you can read more.

    Thx I'll read that

    Is http://www.distantjob.com your website? Cause there are a lot of Cannot modify header information on your site When you look at the source you'll find these error's in the bottom at searchStaff (javascript function) so your javascript isn't working on your site.

  • Users who have thanked Cyf3r for this post:

    DistantJob (02-23-2011)

  • #4
    New Coder
    Join Date
    Feb 2011
    Posts
    48
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Thank you, it's not my site, I'm working for them and they are excellent to work for.

  • #5
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DistantJob View Post
    Thank you, it's not my site, I'm working for them and they are excellent to work for.
    I've read the page you have posted. I'm using an external .jar. So I did use the "Libraries tab" and then "Add External JARs". If I had add it in a wrong way why should my program run like I want it when I use the Run option in Eclipse? Cause thats what I don't understand... In Eclipse everything works fine but when exported it doesn't work anymore :s

  • #6
    New Coder
    Join Date
    Feb 2011
    Posts
    48
    Thanks
    1
    Thanked 2 Times in 2 Posts
    I'm using different IDE and Database Management System when I'm doing my Java projects, so I can only give you general ideas, which might be helpful (I hope so): I think your database runs as a service and a library is needed. Eclipse probably sees the service and links the libraries, when you build your project, these are used correctly when you start your project from Eclipse, but you want to use these without Eclipse, so, the main question I would ask myself in your place is:
    "How does Eclipse run my project?"
    If you find out the answer to this question and you run your project in the same way, your project should work just fine. When you build your project, does Eclipse tell you what command should be used to run the project in command line? If it does, then the solution is simple. I hope my ideas are helpful.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •