I have a Java applet, it works correctly when executed from eclipe, but I want to export it to a Jar and use it. but when I do that, i get jdbc driver not found, it seems like when exporting, jaybird is not exported.
For exporting I use eclipse export and choose Java/JAR File, in build path i have jaybird mark to export.
Any suggestions? Thanks in advance
Use Fat Jar to build runnable JARs that contain all dependent libs
You are most likely missing the files from the META-INF folder of the Jaybird jar file. These files are required for Jaybird to work. Another possibility is that you are missing one of the required dependencies of Jaybird (connector-api-1.5.jar, for Jaybird 2.2 or mini-j2ee.jar for earlier versions).
Even if you get this to work though, you will most likely experience an error later on, as Jaybird wasn't developed with support for applets in mind, see http://tracker.firebirdsql.org/browse/JDBC-254 and NoClassDefFoundError with jdbc applet
BTW: Why don't you just use the jar as is. IMHO creating fat jars including all your dependencies is ugly and inflexible.
I finally get the answer, I had to sign the jaybird jar also because that jar was doing read/write operation in HDD
By using Eclipse you can simply solve the problem.
By going to Eclipse -> File -> Export -> Runnable JAR file and selecting Extract required libraries into generated JAR option, Eclipse will extract required libraries beside your project and creates the required MANIFEST.MF file for you and then will pack them all together in your JAR file.
Related
How do I prevent IntelliJ from including 3rd-party JARs inside my JAR ?
It's insanely annoying. Basically I want one of these:
to produce jar with my code only. 3rd-party jar will be referenced in manifest.
OR
to produce jar with extracted classes of 3rd-party libraries.
The only problem is that IntelliJ produces JAR with other jar files inside. They are useless because java doesn't see them anyway when I run my jar via java -jar my.jar. I have to manually delete them and repack JAR/ZIP file.
Dependencies are not marked as "Export" in Settings.
I think jars end up in my jar because I added "compile output" in layout of my artifact. But I'm not sure how I can make compile output without jars of dependencies.
I tried setting Scope of dependencies to "Provided". It didn't help. They still get copied to output.
Thanks!
This behavior is controlled by the following options when you create a jar artifact in IDEA:
Refer to help for details.
When I clean and build, Netbeans generates a .jar file for my Java project, and it uses a "lib" folder which has all of my external Jar files that I use. Can I somehow tell Netbeans to package these Jar files into the .jar it makes? So that I can run my project as a stand-alone .jar file?
I am using Netbeans 7.1.1 on Mac OSX
The short answer is no, the long answer is complicated.
Firstly, Java does not support embedded Jars (ie, you cann't simply add the depended Jars into the main Jar).
Secondly, uncompressing all the Jars and merging them into one will overwrite any resources/classes that share the same path/name. This may not be an issue in small projects but is a major issue in large ones (we have this problem with the project I'm working on at work).
One solution is to use something like One-Jar, which basically uses it's own boot class loader to all you to reference Jars inbedded within a single Jar.
I've had issues with this when using our own custom classloader, but otherwise it seems to work well.
It includes Ant support, so you can include it in your projects Ant build script, if you not using Maven, otherwise, you'll need to devise your own build process
There is no options in netbeans to do that.
There are some other options that a quick search would help, but requires manual intervention.
I have a java application I've written in eclipse. It works fine there.
It works fine run from a command line in the directory where I export it to. In that directory is another directory containing two jar files that I need for the application, and the manifest file has a Class-path option specifying them.
I want a way to use eclipse to generate the necessary file(s) to package this application to run on another machine. Is that possible?
If I choose "create executable jar file", it creates this huge file; it does unpack and repack the two libraries, which I know is one way to get their functionality included. I would actually prefer it if they were left as their own jars somehow, but I am not certain eclipse can do that. More annoying is the fact that the executable jar file option puts lots of files from my eclipse project into that jar file. I don't see an option to choose what gets included there, though I do see a place to enter inclusion and exclusion "rules' in the project properties. Do those apply here? Is there somewhere else I go to select what does and does not get included in the "executable jar"?
If I choose "create jar" (ins of "create executable jar"), I don't see where there's an option to include these two jar files anywhere. Perhaps there is no place to include them where they could be used.
If possible, I do not want to use Ant, I do not want to use Maven, I do not want to download another tool. It seems to me that Eclipse already has all this information and I suspect it can already do this without having to go and learn yet another "nifty" tool.
Eclipse has its own Jar export wizard for generate a runnable jar packed with required library or with the required library in a folder aside the jar.
Going in File ---> Export then choose Java - Runnable Jar
You can then choose how pack the jar and how handling libraries :
You can also save the ant script for later modification or use ...
You actually should use Ant or Maven for your task, I see no other option. Ant is already packed with eclipse, you only need to install a JDK, not only a JRE.
Ant is very easy to learn and you can find billions of examples in the internet. With ant you can do exactly what you want.
Maven is the more up-to-date way to build and package jars and do much more other stuff. Maven also is a good choice for you.
I'll second a vote for Maven. Eclipse has a decent maven integration (m2eclipse). Then check out this answer for building the jar effectively using Maven2
Building a runnable jar with Maven 2
Specifically, I am using JDBC libraries to work with databases in my Java program. When I perform "Export Runnable Jar" in Eclipse, it includes the referenced libraries but I am never given an option to include my assets folder (containing the databases) in the runnable jar file. If I try to export a regular jar file via Eclipse, I can add the assets folder, but the referenced libraries are not included.
What should I do here?
Thanks a lot.
Try using Ant scripts or maven script to do this.
Where you can import all the referenced jar and files to your desired location.
Personally i liked ant script, since it was easier and you will surely get lot of results for the same if you google.
Are your asset directories declared as Source Folders in Eclipse?
Right Click on the folder, choose Build Path->Use as Source Folder. Then retry the export.
In the longer term, you should really be looking at a build tool such as maven or ant, they are much more flexible, and they are less dependent on Eclipse, so changes in your project configuration in Eclipse won't affect the final build so much.
It's been some time since I last generated a JAR file with Eclipse, and back in the day I remember the Fat-Jar Eclipse Plug-in to be quite useful.
We used an external library, specifically jmf.jar (Java Media Framework), for our java application which relies on images captured from the webcam. However, when we tried to package the application into a jar file, the application runs but once we try to access/open the webcam nothing happens.
We are using Eclipse and we used its export feature to create the jar file.
Does anybody know how to solve this?
Did you think to include jmf in the manifest of your jar ? See this link for more explanations here
You don't just need to export your project into a jar file; you need to create an "executable" jar file. This means that the manifest of the jar file is edited appropriately so that the classpath includes all required dependencies and the main class is set correctly.
In recent versions of Eclipse you can use the Runnable JAR File Export Wizard. Have also a look at the Fat Jar Eclipse Plug-in.
If you are using JMF you’ll need to include jmf.jar and jmf.properties in the same directory as the executable jar