Including the JAR in the same folder to maintain consistency - java

I have the JAR files in Netbeans as follows:
However, when I check in the Properties section after right clicking on the Netbeans Project, my sqljdbc4.jar is some what different from the other JAR files, I mean it's path is different, since I added it afterwards as shown in the image below:
1) I have got a feeling that, since the path is different, I am not able to connect to SQL Server.
2) Also, when I would have to send the whole project to someone, this relative path won't work I believe. Is there a way, I can insert sqljdbc4.jar inside the src/bundle_includes folder just like the other ones? Please advise. I am using Netbeans 7.4

It seems that when you have added the sqljdbc4.jar it was on the desktop, so Netbeans linked it letting your source code compile, but this don't include the jar into your src/bundle_includes.
You should:
manually copy sqljdbc4.jar into src/bundle_includes
removing the sqljdbc4.jar with bad path from the Compile panel
click Add JAR/Folder and choose src/bundle_includes/sqljdbc4.jar

Related

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver [duplicate]

I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.

`java.lang.ClassNotFoundException` when run it in cmd [duplicate]

I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.

JFreeChart Java JAR not running on a different machine

I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.

JAR File not exececuting which is build by netbeans

I am a Beginner in Java GUI and am using Netbeans 7.3 to use Swing Components, the problem is that all was working fine, but one day when I Clicked Clean & Build and tested the JAR file, it was not executing, I ran it in the Netbeans and It is working fine.
Then I thought that it would be a problem of Build Properties so I compared build properties from a project which was working fine with Jar file but I cannot find any difference, The problem is that when I double-click the JAR file, no Error is shown, I tried many ways like executing it from cmd but It did'nt worked.
Can anyone help me out What could be missing, and one thing more that is I even tried to build my project on another computer through Netbeans but no use.
Try to open your .jar with winrar, and check if the classes are being added to the .jar, If they are not being added probably is a bug from netbeans, I would advise to install netbeans 7.2, and then open your project again, and then regenerate the Jar File. I was having a similar problem with Netbeans 7.3
I think you executing .jar file from different folder - not from where it was created? If so - that means your application can not find some files - pictures, etc. So if you have some files which application uses - create the folder named "lib" and place there your files - but not .jar file. For example:
File file = new File("/images/etc.png");
means that it is placed in lib/images directory. So your .jar file could be run from here:
C:/myTestApplications/myApp.jar
which contains also folder
C:/myTestApplications/lib/images
Try that.

java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable

I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself.
My classpath looks like this-
C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar
I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.
The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDEs like Eclipse, Netbeans and IDEA.
That environment variable is in real world also considered a poor practice since it breaks portability. I.e. program X will run successfully while program Y won't run without altering the CLASSPATH. It's only "useful" for Sun Oracle to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments when following Java tutorials. In real world, batch/shell files are preferred where just the entire command with -cp/-classpath argument is specified.
In your case you're using an IDE. The classpath is there called the "Build Path". In plain Java projects, it represents both the compiletime and runtime classpath. You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget about using the CLASSPATH environment variable. It was a mistake by Sun Oracle. They thought to convince starters, but it ended up to be only more confusing to starters as they incorrectly interpret that environment variable as the classpath.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.
What worked with me using Netbeans was:
Run > Set Project Configuration > Customize.
Under Libraries > Add Library. Added MySQL JDBC Driver (I assume it appeared in list because I copied the jar file to the jre\lib\ext folder.
And it worked seamlessly.
I tried setting classpath but that did not work. I am using Netbeans 7.0
simply do a right click on your project in "Netbeans" select properties then click on "libraries " then click on "add library..." button then select "MySQL JDBC Driver" and click on "add library" button then on "OK" button
I also had this problem before, but after I put/added mysql-connector-java-5.1.34-bin.jar (Download it from here) into the apache-tomcat-8.0.15\lib folder, and then ran my project, it really did work.
Note : Even after adding the jar file the error persists, then restart the Tomcat server and rerun you project again.
Open Netbeans IDE
Right-click your Project.
Select Properties.
On the left-hand side click Libraries.
Under "Compile" tab - click Add Jar/Folder button.
Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com)
Click OK
Run Again... Its work.
If you are using maven, add the dependency to pom.xml should solve the problem.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.
I had this same problem in Netbeans. Because I was using a tomcat connection pool as defined in context.xml I needed to add the jdbc jar to both the project (Properties->Libraries) and to the lib/ folder within my Tomcat server so it could be seen on startup.

Categories