Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2011, 02:52 PM   PM User | #1
Cyf3r
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Cyf3r is an unknown quantity at this point
.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();
		}
	}
}
Cyf3r is offline   Reply With Quote
Old 02-23-2011, 03:37 PM   PM User | #2
DistantJob
New Coder

 
Join Date: Feb 2011
Posts: 48
Thanks: 1
Thanked 2 Times in 2 Posts
DistantJob is an unknown quantity at this point
If you link your library correctly, there shouldn't be errors.

Here you can read more.
__________________
Distant Job
DistantJob is offline   Reply With Quote
Old 02-23-2011, 04:09 PM   PM User | #3
Cyf3r
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Cyf3r is an unknown quantity at this point
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.
Cyf3r is offline   Reply With Quote
Users who have thanked Cyf3r for this post:
DistantJob (02-23-2011)
Old 02-23-2011, 04:12 PM   PM User | #4
DistantJob
New Coder

 
Join Date: Feb 2011
Posts: 48
Thanks: 1
Thanked 2 Times in 2 Posts
DistantJob is an unknown quantity at this point
Thank you, it's not my site, I'm working for them and they are excellent to work for.
__________________
Distant Job
DistantJob is offline   Reply With Quote
Old 02-23-2011, 04:17 PM   PM User | #5
Cyf3r
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Cyf3r is an unknown quantity at this point
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
Cyf3r is offline   Reply With Quote
Old 02-23-2011, 05:05 PM   PM User | #6
DistantJob
New Coder

 
Join Date: Feb 2011
Posts: 48
Thanks: 1
Thanked 2 Times in 2 Posts
DistantJob is an unknown quantity at this point
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.
__________________
Distant Job
DistantJob is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:27 AM.


Advertisement
Log in to turn off these ads.