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
Related
I have downloaded .jar drivers for a portable printer and I have placed them under the libs folder at Android Studio 1.0.2. Normally other .jar files have this ▶ to right triange next to them but these ones don't. May be they need some kind of META-INF?
Why Bixolon Printer has no triangles?
Why I cannot import the com.bixolon?
Not all jar files need a manifest.mf file. A manifest file is intended to make it possible to point an application to an entry point, so the .jar can be executed as a standalone application.
Other .jar files, however, are not meant to run on themselves. They are supposed to be class libraries, to be imported and used in other projects.
You need to add those jars as libraries to your project; simply putting them under the "libs" folder is not sufficient. Specifically, you need to add something like this to your build.gradle:
compile files('libs/bixolon_printer.jar')
Once you do that, reimport your project in Android Studio.
Make sure you are importing the right package.
I downloaded the same library and imported "com.bxl" instead of "com.bix"
Try reading the printer's API and sample source. :)
I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html
I have made a utility java project which contains XML, DB and other such utility classes. This requires 3rd party dependencies on some of the Apache common libraries, so I have added it in my java project by configuring the build path in eclipse Juno. Now I want to export this java project as jar file. When I am exporting this project as runnable jar file, it is working fine i.e if I include this jar in some other java project, I am able to access the utility classes, but when I am simply exporting the utility project as jar, I am not able to use it. Runnable jar requires a main class, but I don't want to keep a main class in my utility java project. I have compared both the jar files. The difference that I found out was that in runnable jar file, there is no .classpath file but a simple jar file that is in there. In the runnable jar file, all the jar files are mentioned in file named MANIFEST-INF.mf file, but in simple jar file it contains only version of .mf file. Can anyone tell me how can I make a jar file without a main class and use it for my other java projects so that I just have to include the jar file and use it as it is.
I assume it has not been provided in eclipse because extracting external 3rd party library classes in a utility project is something non-standard. It can result in a lot of problems as your project grows, class conflicts being one of them.
Still if you want to continue with your approach, yon can export your project as a normal jar project. Thereafter after open your project as well as the other third party libs in a utility like 7zip and drag-and-drop your third party library contents(except META-INF) into your project jar. That's all.
If you however want to automate it, ant would be your friend.
If you just export the project to jar file, you can package the jar(war) by using the apache ant tool.
Do something like this:
<jar destfile="${dist}/lib/app.jar"
basedir="${build}/classes"
excludes="**/Test.class"
/>`
I have a little problem importing a project to my android project.
I have built a little library using Ical4Java to parse a .ical file, and that library is exported to a .jar.
In my Android Project i have imported and added to the build path my generated .jar from my library that includes some jars to make my library work.
But when i run my application it just crashes and i get this on the LogCat:
E/AndroidRuntime(14382): java.lang.NoClassDefFoundError: net.fortuna.ical4j.data.CalendarBuilder
That library (ical4j.jar) is imported on the library buildpath and is exported whith my library (mylibrary.jar)..
You can use One-Jar to help you use a jar file that is dependent on other jar files. Basically you can combine them into one jar file.
Here is a little tutorial to help you.
Just put the content of the one jar into the other jar (combine them). They are just zip files.
Is mylibrary.jar an executable jar file?
If so, you cannot reference external jars.
Well I have 2 .jar files. The main jar file is the jar file for my whole project and the other .jar file being the MySql JDBC Connector.
Well basically whats happening right now is that when I build the project I have the one main .jar file with everything but the MySql JDBC Connector .jar file is inside the main jar file when it builds in NetBeans.
Now when I am just running the project from within NetBeans the MySql JDBC driver can be found inside the src/com/game/mysql folder that I have it in. But when I build the project the Java application cannot locate the JDBC driver from within the main jar file.
When I open the main jar file with WinRar I can see that the JDBC jar file is still in its /com/game/mysql/ folder. But why cant the Java application access it?
I have heard that nested .jar files are not supported in Java so Im thinking this might be the reason although Im not sure if thats true. Is there a way that I can make it so that the application can find the JDBC .jar file within the main jar file?
Also I have done the thing in NetBeans where you add the .jar file through right clicking project -> properties -> Library -> Add Folder/Jar. Thats what makes it work in the NetBeans run but still not the App build.
I have heard that nested .jar files are not supported in Java
More precise, classes in a JAR file which is packaged as a child JAR inside a main JAR are indeed by default invisible to classes in the main JAR.
You have basically 2 options:
Ship your application with 2 loose JARs: your.jar and mysql.jar and define the relative path to the mysql.jar in the Class-Path entry of the MANIFEST.MF file of your.jar.
Class-Path: mysql.jar
When you put both JARs in the same folder and execute your.jar by java -jar your.jar, then it will work.
Let your IDE repackage all loose classes of mysql.jar inside your.jar or add a special classloader which preloads the classes of any embedded JARs. Since I don't do Netbeans, I can't tell whether it supports it and if so, how to do it. In Eclipse, however, this is definitely possible. See also this answer.