JDBC ClassNotFound even with MySQL library - java

So I am trying to connect to my server, I had it working before but now I moved to a different machine it's not working as you can see below.
I have added the MySQL driver into my path and I'm not sure what the problem could be.
Any ideas?
Thanks.

You indeed have defined that MySQL connector is a library for your project, but you also need to add it as a module dependency on the Modules tab in Project Structure.

If you haven't dependency management such as maven (gradle, etc), create lib folder in project root folder. Move jar to lib folder and right click on it and select "Add as library".
This should help you.

Related

jar libraries not updated in eclipse with git

I am developing java projects in eclipse and version controlling with git.
What I found today was that the jars of user library was not being updated after pulling a project from git server to another repository/directory. The newly exported jars after adding new classes or functions were not recognized.
So I removed the user library with the problematic jars. The eclipse java project still has access to the jars.
Create a dir.
Git init
Create an empty java project
Pull from git server
The above is the steps that caused this problem. I didnt commit the empty project before pulling.
Thanks~
Have you tried refreshing the project? (Right click on your project and then select Refresh)
Your changes done to the file system (pulling stuff from git) are not known to to Eclipse, so you have to explicitly tell Eclipse that it has to refresh its idea of what are on the file system.

Hibernate + Maven + MySQL Connector

I have a little bit of a problem here.
When I started a new project in Eclipse for instance, I add a new dependency with Maven to manage the MySQL connector dependency.
But when I configure a new Driver Definition, it says that it is unable to locate JAR/zip file of the driver definition mysql-connector-java. But as long as I understand it is manage by Maven so it should be anywhere on the Eclipse project right? If I have to downloaded manually and save it on my local drive what is the use of manage that dependency with Maven?
Not sure about maven, but I use Gradle... In these cases, what happens, there is a .gradle folder available.
We normally delete the ...users/.gradle/files/cache/{project} contents from the same path and do the gradle refresh. You can try with the same.

Including external jars permanently in NetBeans

I'm building a Java Swing Application. This project requires a jar file called JCalender. I've added this to Libraries folder and everything works fine on my computer in NetBeans. But when i open the same project in my friends NetBeans, it doesn't recognizes this library. I've to manually select the file placed inside the projects dist/lib folder. How to avoid this? please help!
But when i open the same project in my friends NetBeans, it doesn't
recognizes this library. I've to manually select the file placed
inside the projects dist/lib folder. How to avoid this?
You can't avoid this because it's not a problem actually. To compile and run a project you need to have access to the external libraries involved in the development, so if you open your NetBeans project in a different computer than yours you will definitely need to resolve the reference to the external libraries. There's no way for the IDE to do it automatically as far as I know.
Can't i give the relative path to the lib folder for that specific
library somewhere in project properties?
You could just give it a try. IMHO if the real goal is to share a project with other developers then I'd change the strategy. I'd create a Library (Tools -> Libraries) and tell my mates to create the very same library including the JCalendar JAR files in the library's classpath. I'd include this library in the project properties and finally I'd use a versioning tool like Git or SVN to share the project.
By doing this your mates still need a copy of the JAR file wrapped in a NetBeans Library, but the project properties won't point to a fixed/relative path looking for a JAR file but wil include a reference to a given Library. The Library itself will resolve the dependency to the JAR file. If you take a look to the project.properties file you'll see something like this:
javac.classpath=\
${file.reference.jcalendar-1.4.jar}
But if you as I've suggested then you'll see something like this:
javac.classpath=\
${libs.JCalendar.classpath}
Here libs.JCalendar.classpath will resolve the dependency so your mates can have the actual JAR file located in whatever folder they like and the project should compile just fine.
Another option is using Maven to manage the projects dependencies but honestly I'm not a Maven expert so I can't help you in this path.
You need to do a "clean and build" and your jar will be in the dist folder. It will include the external jars
You can read more about it here
I think your problem is due to you are providing absolute path of jar file.
while choosing jar on write side of filechooser there is option of
Relative path and Absolute path there you should click on Absolute path.
i am new to java , but anyway , i have faced the same problem and found a solution for my project
If you are in Netbeans , its would be very easy for you
Let you project name is ABC and all your dependent jar file is under the
the folder MyResourceCollection
now we need to permanently import all jars under this folder ,
So from Netbeans ,
right click on your project name
go to properties
go to library
in the library page , check the "libraries folder" label
you can find a browse button at the right side of the label
click browse and select the MyResourceCollection folder
a new window will come , just press Next-->Next--->Finish
all is done , now check yourself by moving the folder into different location

why I can use the sources or jar downloaded in my project?

I am trying to use Maven and JDeveloper for a week now and I'm always get stuck with the same problem. I can download and install the extensions and create new Maven projects. When I package or compile them I can see that the sources are being downloaded and added to my local repository but they are not added in my .jar and I cannot use them in my project unless I add them as lib manually in my project.
If I try to add the folder (where the downloaded jars are) as lib folder to project they are only added as jar and I cannot use them.
Is there another way to update my dependencies from JDeveloper? How can I integrate them properly to my project so I can use them? Is there a newer Hands-On maybe solving my problems? What am I doing wrong? Is there a template project to download maybe? I hope I could explain my problem good enough...

Required Java libraries in Eclipse when working on multiple OSs

I'm developing an AppEngine project in Java.
I'm working on a MacBook and on other two PCs.
I'm using a hosted SVN as my RC.
I included some libraries from the GAE plugin in my project:
gwt-dev.jar, gwt-user.jar', validation-api-1.0.0.GA.jar.
I did that in the Java Build Path in the project properties.
Every time I switch a computer, I get an error:
Project '' is missing required library: ''. Off course, the path is changing between computers.
How can I resolve this issue?
Should I remove this settings from being stored on the SVN repository? If I shpould, how can I do that?
You should not persist any user-specific path information. Set your projects up by hand and then check out the user-agnostic stuff.
We have the same problem with IntelliJ. The answer is to check in only user-agnostic information, or get an IDE that's smart enough to use relative paths.
If you add 3rd party libraries to the project, make sure they are copied into your /lib directory and not in a path that's unique to you.
Create a project for the libraries.
Put the libraries in the project.
Export the jar files.
Set this newly created project as a dependency in the main project.

Categories