Creating jar from java project which uses jdbc - java

I have finished my java application using eclipse, with some sql code. I am using oracle database and jdbc connector.
When I am trying to create a jar file it shows me this message: JAR export finished with warnings.
See details for additional information.
Exported with compile warnings:
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-path entry for 'C:Users/Grlouk/Downloads/ojdbc6.jar'
And when finally I am creating a.exe file from .jar database functions does not work. Any suggestions?

It would appear that the exporter is looking for the JDBC library ojdbc6.jar in your C:\Users\Grlouk\Downloads folder and finding it missing.
There are a couple of ways to fix this.
1) Find where your ojdbc6.jar file is located and put it in C:\Users\Grlouk\Downloads
2) Change the classpath to reflect the actual location of ojdbc6.jar file, e.g. if you are using the Eclipse IDE you can right click on your project and Build Path > Configure Build Path... to open the build path configuration and then under the Libraries tab you can manage the libraries, and under the Order and Export you can explicitly state which libraries will get exported, you might want to select the ojdbc6.jar here if it please you.

Placing jar inside a jar won't work. You have to use it with some third party libraries. Because when you are trying to executing the jar file it tries to search the jar files in the mentioned path. Jar file will not be present in the path so classpath fails. Do it with eclipse by exporting to jar.
Eclipse will load the jar files on the fly and add it to your classpath.

Related

How do I add a .jar file into an IntelliJ IDEA Java project?

I have a java project loaded into IntelliJ IDEA. The code requires JDBC and so I downloaded and unzipped the sqljdbc_6.4.0.0_enu file into the recommended directory, "C:\Program Files\Microsoft JDBC Driver 6.4 for SQL Server". This creates the jar files:
mssql-jdbc-6.4.0.jre7.jar
mssql-jdbc-6.4.0.jre8.jar
mssql-jdbc-6.4.0.jre9.jar
in the directory, "C:\Program Files\Microsoft JDBC Driver 6.4 for SQL Server\sqljdbc_6.4\enu". And so, now, how do I make use of all this in my project in IntelliJ IDEA? And if I later put all my java code into Git Hub, how can I ensure that another user will have code that will compile and link? Will I have to include the .jar file in Git Hub somehow?
you should not do this. For your case, you can choose one of them:
create lib foder into project folder - put .jar files in the folder- setup module with library point to the folder - commit metadata folder of IDEA such as .idea, {projectName}.iml (not recommend)
The best solution is using maven or Gradle, you are able to put the dependencies which are neccessary into pom.xml file. (Recommend)
You can refer this for adding external jar files in IntelliJ IDEA.
As for GitHub, you can put your jar files there by removing *.jar from .gitignore configuration file. However this is not a recommended practice to have JAR files in repository as they've considerable size. You can consider using some build tool(maven or gradle) to add external dependencies.

Ant Java Build Path set by Eclipse is Missing a Library at Compile Time

I'm using eclipse and ant to compile a java project. The ant compile script calls javac using a classpath refid of classpath, which is set based on System Property variable java.build.path.
My java.build.path variable is missing a library that was specified in
Project->Properties->Java Build Path->Libraries.
That is, the external jar was properly added to the list of libraries to add to the build path, is not missing or corrupt, and I have every expectation that eclipse would include the library in the build path. My build fails because java.build.path is missing this library.
Furthermore, the file <projectDir>/.classpath contains a valid classpathentry element for the missing jar file.
When building, javac fails at an import statement, claiming that the package does not exist. The value of java.build.classpath contains many of the libraries I set in the project properties, but does not include the missing library. Its as if the project property for that external jar was never set.
For what its worth, the missing library is jboss/lib/jbosssx.jar
Any help here would be appreciated.
At first,
Download jbosssx.jar jar file from this link
Then keep the jar file in the folder jboss/lib
Hope it will solve your issue.
UPDATE:
Sometimes jar files need to keep in lib folder physically. For this reason, you can put the jar file in your project lib folder.
I found where my configuration was messed up.
Using External Tools Configurations within eclipse, I found another Classpath settings tab for my ant build that did not contain my library.
Adding my library here caused the build to succeed!
Skywalker, thanks for the suggestion. :)

Derby embedded driver - "Class not found" after exporting to application to JAR

I am trying to get Java working with Apache Derby embedded database, and it works fine in eclipse but gives the error
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
when exported to a Jar file and run.
I included the Derby Jar in my project by adding it to the lib folder then referencing it in the build path, so that the jar is in the referenced libraries folder.
Any ideas on how to fix this?
When exporting from Eclipse, the "JAR file" destination will only include your own classes and not the external dependencies they require. To include those dependencies you need to choose "Runnable JAR file" as the destination.

Adding External jar's in Eclipse

I have created a program to connect to MySQL. I add Connector/j using eclipse add external jar option. Program works fine in eclipse. But when I created the executable jar using eclipse and when i run it, it always give ClassNotFoundException. Please tell me how to add external jars to my jar. Or is there any other error? Please can anyone help me.
The simplest solution is to export your project as a 'Runnable Jar file' (Right-click on project->Export...->Runnable Jar file) that will place all dependencies in one jar file.
Otherwise you will need to include a classpath to the additional jars either in the manifest.mf file or on the command line with the -cp option.
java -cp .;myjar.jar;mysql.jar my.package.classname
You need to create a jar that includes the files from all the dependent jars. The classloader won't be able to find the classes if you simply include the jar files themselves inside the executable jar. There is an eclipse plugin called FatJar that does this.
http://fjep.sourceforge.net/
You can simply add the class-path element to your jar MANIFEST and list your external jar inside the MANIFEST
like this:
Manifest-version:1.0
Class-Path: class0.jar
class1.jar
class2.jar
class3.jar
class4.jar
...
One jar per line.

Add python module to JAR classpath in Eclipse

I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-path entry for 'C:Projects/this_project/src/com/company/python/'
When browsing through the generated JAR file with an archive manager, the python module is in fact inside of the JAR, but when I check the manifest, only "." is in the classpath. I can overlook this issue by manually dropping the module into the JAR file after creation, but since the main point of this project is automation, I'd rather be able to configure Eclipse to generate properly configured JAR automatically. Any ideas?
*NOTE*I obviously cannot run the program successfully when I do this, but removing the Python source folder from the classpath in "Run Configurations..." makes the error go away.
Figured it out, had to add the source folder with the Python module in it as a class folder in the Build Path project properties. Not sure if this next part is necessary or not, but since the module is not compiled, I added the folder again as "Attached Source" after adding the class folder.
Have a look at the maven-jython-compile-plugin and its demo project at http://mavenjython.sourceforge.net/ . It allows bundling jython with dependencies into a standalone jar.

Categories

Resources