Creating installable application from Java - java

I've been trying to create an installer for a while now, and everything seems to work except adding external .jar files. My application imports the com.mysql.jdbc.Driver, in order to connect to the inbuilt MySql DB, But whenever I try to start the program via launcher (after installing), exceptions are thrown stating the mysql connector driver cannot be found. Would be glad if anyone could tell me the most straight-forward way to include external .jars with installer4j

Just solved the problem. It seems that external .jars need to be added individually on Step 3 in the classpath

Related

Error while starting a runnable jar: No suitable driver found for jdbc:sqlite

I have only the jar-file of an application. While starting it, i get the following message:
No suitable driver found for jdbc:sqlite:...path_of_the_db.
I already checked similar questions and am confident that it is not a dublicate.
According to the link SQLLite Jar need to be put the in the CLASSPATH of the app.
Now my problem is how to put the SQLLite Jar in the Classpath of the app. Besides the solution which is sketchilly explained here. Because you always need to search for the location of the SQLLite on the system and also type it in the console any time you start the app. (I don't have the source code of the program.)
Another question is if there is any possibility to include the SQLLite Jar while creating the Jar-file for the application. If it is not the case maybe there is another option which allows to create a runnable jar without setting the Classpath on foreign systems?
Thanks

Access derby database in executable jar

I have been looking for a while now but haven't found exactly what I want. So, I have a project written in Java and have created a small Derby database that I have embedded in the project. Now when creating an executable jar of the project, I cannot access the database anymore unless I put the derby database files in the same directory of where the executable jar is located. However, I do not want this, I really want that the database files are INSIDE the jar.
I have tried to put the database files in a package and reference it like that, without any luck. Could someone point out how I can get this to work please?
Thanks!
EDIT
The goal here is that I want to create more than one executable JAR file and upload them to a Sun Grid Engine and execute each jar with different parameters. However, they all need to be able to access the database and until now I get an error when 1 application already booted the derby database, another application cannot access it. Therefor ALL jar files need to have their own database.
Do you use the jdbc:derby:jar protocol to access your database?
According to the documentation what you're after should be possible.
Inside your app (the one going into the executable jar) you must access the database using the jdbc:derby:jar protocol.
Create the database with the desired content.
When you have built your jar, you can use jar commands to add the database dir to your jar.
All of this could go in your build script, obviously..
There may be issues related to jar sealing and such, YMMV.

even with ojdbc14.jar in Build Path, Class.forName("oracle.jdbc.driver.OracleDriver") gets ClassNotFoundException

I'm trying to make an servlets application with java and oracle10g and I've had it well so far until I need some specific values from some the database, for wich I have a DAO class that handles the connection for retrieving data. I have the following issue.
First off, I excecute a main() method in this class that is suposed to retrieve all entries in some table an print the name of each one in console. I works perfectly.
then I want to return an ArrayList of all those names in order to use them in the servlet. So I make a method just like the one in the main() with the only difference that instead of printing the names, I add each one to an ArrayList which is returned after closing the conection. Well, It gets ClassNotFoundException in the line Class.forName("oracle.jdbc.driver.OracleDriver")
If it helps, I'm guided with this tutorial to connect java applications to oracle databases.
Any help would be appreciated
Put ojdbc14.jar inside your war file at WEB-INF/lib/ directory. You can use ANT task to do this. If you are unfamiliar with ANT, you can just copy the jar file inside WEB-INF/lib/ directory under your project and just zip it using Windows explorer or WinZip or anything else that works for you. Then rename the .zip file to .war and deploy on Tomcat server.
If you want some quick fix just copy the ojdbc jar file to server/lib directory under tomcat and restart tomcat. It should work.
EDIT: refer the comment below. While personally I have not seen any unexpected behavior with JDBC drivers in web-app classloader, but, it is recommended to keep driver jars under Server lib.

How to load a resource from compound JAR?

I have the following problem:
I am writing an application that uses some of the JARs from the Netbeans Platform. To be exact, I am only using the Netbeans Visual Library for creating some graphs. This can be done without using the Netbeans Platform by extracting 3 JARs from the platform. This is all working well, except for 1 problem.
Some Background
I am using the Java Simple Plugin Framework (JSPF) to handle my plugin management. So I have an application that basically consists of a skeleton framework, and then depending on which plugin JARs it finds, it can do various things, one of which is drawing graphs. The JAR plugin for this functionality has all it's dependant libraries inside. This is done by exporting the JAR as an artifact in IntelliJ, which will unJAR all the dependant libraries and reJAR them inside yours (so everything you need is there).
The Problem
What seems to be happening though, is that when it tries to start use the classes from the embedded libraries, it works fine, but when it needs resources (.png specifically in my case), it complains that it cannot find it.
My Thoughts
The only thing I can think of why it is not working, is that it could be since the plugin JAR is not in a classpath. Could this be it?
Is there anyway to specify a classpath directory in the MANIFEST maybe? Otherwise must I create my own ClassLoader and manually load all the JARs in the plugins directory?
Thank you!
UPDATE:
I have subsequently pinpointed that it is indeed a problem with the classpath. If I place my compound library on the classpath, everything works perfectly. The problem I experience now though is:
If I copy the library to /Library/Java/Home/lib/ext/ it works fine. If I execute the application with java -cp "/path/to/plugins/myLib.jar" -jar Application.jar it does not work.
How can I load all the jars in the plugins directory into my application so the resources inside them can be used?
Thanks again!
So I have finally figured out what was happening. When creating a executable jar, the MANIFEST.MF file overrides any classpath you specify in the command-line, which basically renders it useless if you want to specify external jars. This seems to be a general problem that has been logged since Java 1.3 already.
My simple solution is to simply not create a executable jar, and then launch the application with a script:
java -cp App.jar:plugins/* my.package.structure.App
which works perfectly.
The default classloader's do not load classes in nested jars. You'll need to write your own classloader to get the classes in the nested jars.
You can check out this jspf article...
"I forgot: Adding dependencies as JARs inside JARs is not possible, because it would not work in all scenarios (e.g., applets); IIRC also tools like Eclipse would have problems if you used classes with unresolved (read: runtime-resolved-dependencies). To my knowledge there is no established way yet to gracefully handle nested JARs in all circumstances."
http://code.google.com/p/jspf/wiki/UsageGuide

jTDS - No Suitable Driver Exception when running a Maven built project

We have a simple [spring-hibernate] application (console app) where in we have set the classpath in manifest file of the executable JAR file. And the app connects to the database using jTDS JDBC Driver, Everything works as expected on Windows machine and JDK 1.6, but on Linux, the app is unable to find the driver,
We are running the program using java -jar MainClassName.
Any suggestions why this might be happening is greatly appreciated.
This issue occurred because our jdbc.url had invalid url. This was because maven treats jdbc.url property as a special property and while profiling, instead of url defined in the filter.properties. And that is the reason "No Suitable Driver" exception. The question should have been more clear.
Anyways to fix that we had to rename jdbc.url properties to jdbc.url.somename. This fixed our issue with maven profiling. We also had a similar maven profiling issue for a property called "server.name" This filter property was also confusing maven profiling . We had to change the name of that property as well.
Thanks again Fernando.
Honestly it sounds like bad CLASSPATH. One thing I suggest to start debugging this problem is copying the jtds package to same path as your main packages/classes and see if it works. This way you can assure the Classpath manifest is or isn't the problem. The Spring/Hibernate relies on the lib directory, so it will always be on classpath because it's main structure. Use the lib directory also to test.
Hope this guidelines will help. Also send more information, like paths, classpath and manifest files.
It is a Maven bug
http://jira.codehaus.org/browse/MNG-3563

Categories

Resources