Creating Android .jar files - java

I want to create an Android project that contains some code, and then export that code as a .jar file to use it on another Android project.
I've already tried to create an Android project and set it as a library in the properties, and then export the project as a jar file. Aparently everything works fine, when I use my .jar file as a user library in another Android project my code inside the .jar is visible and everything compiles fine. But when I run my application it closes and say that it could not find the classes inside the .jar file.Any sugestions will be very appreciated!Thanks in advance.

Look at Project->Properties->Java Build Path->Order and Export. Make sure your jars are exported as well as imported.

Make sure your JAR is in the libs/ directory of the project using the JAR, and that it is in your build path in Eclipse.

Related

How to execute commands of an application in jar when the app is placed in jar?

I have a project built by maven that needs to call commands of an application(named qvality). So I added the app into directory resources(myproject/src/main/resources/qvality). Then I package the project with jar. In code, I use this.getClass().getResource("/qvality").getPath() to obtain the app path. However, the way is failed because of the path problem. The path is /home/user/pipeline-reconstruction-1.0-SNAPSHOT.jar!/qvality using this.getClass().getResource("/qvality").getPath().
So I want to know how to get the correct path of the app in jar? Or is there a better way to implement my desire?
You need to open the .jar with winrar(or other software) and insert your file. because when you export your project the file in the res folder are not export in the jar file.

How to add External libaries to jar in intellij

to work with mp3 files on my project in Intellij I needed to use mp3spi libary. So I added it to my project libaries and everything works great when I compile my application inside IDE, but, when I build artifact it does not have my external libary inside jar file so it does not read my mp3 file. I also added them to my artifacts output path but maybe I did something wrong. I am stuck, please help.
Project structure screen

Including external jars permanently in NetBeans

I'm building a Java Swing Application. This project requires a jar file called JCalender. I've added this to Libraries folder and everything works fine on my computer in NetBeans. But when i open the same project in my friends NetBeans, it doesn't recognizes this library. I've to manually select the file placed inside the projects dist/lib folder. How to avoid this? please help!
But when i open the same project in my friends NetBeans, it doesn't
recognizes this library. I've to manually select the file placed
inside the projects dist/lib folder. How to avoid this?
You can't avoid this because it's not a problem actually. To compile and run a project you need to have access to the external libraries involved in the development, so if you open your NetBeans project in a different computer than yours you will definitely need to resolve the reference to the external libraries. There's no way for the IDE to do it automatically as far as I know.
Can't i give the relative path to the lib folder for that specific
library somewhere in project properties?
You could just give it a try. IMHO if the real goal is to share a project with other developers then I'd change the strategy. I'd create a Library (Tools -> Libraries) and tell my mates to create the very same library including the JCalendar JAR files in the library's classpath. I'd include this library in the project properties and finally I'd use a versioning tool like Git or SVN to share the project.
By doing this your mates still need a copy of the JAR file wrapped in a NetBeans Library, but the project properties won't point to a fixed/relative path looking for a JAR file but wil include a reference to a given Library. The Library itself will resolve the dependency to the JAR file. If you take a look to the project.properties file you'll see something like this:
javac.classpath=\
${file.reference.jcalendar-1.4.jar}
But if you as I've suggested then you'll see something like this:
javac.classpath=\
${libs.JCalendar.classpath}
Here libs.JCalendar.classpath will resolve the dependency so your mates can have the actual JAR file located in whatever folder they like and the project should compile just fine.
Another option is using Maven to manage the projects dependencies but honestly I'm not a Maven expert so I can't help you in this path.
You need to do a "clean and build" and your jar will be in the dist folder. It will include the external jars
You can read more about it here
I think your problem is due to you are providing absolute path of jar file.
while choosing jar on write side of filechooser there is option of
Relative path and Absolute path there you should click on Absolute path.
i am new to java , but anyway , i have faced the same problem and found a solution for my project
If you are in Netbeans , its would be very easy for you
Let you project name is ABC and all your dependent jar file is under the
the folder MyResourceCollection
now we need to permanently import all jars under this folder ,
So from Netbeans ,
right click on your project name
go to properties
go to library
in the library page , check the "libraries folder" label
you can find a browse button at the right side of the label
click browse and select the MyResourceCollection folder
a new window will come , just press Next-->Next--->Finish
all is done , now check yourself by moving the folder into different location

Why some of the .jar files in an Android project does not have META-INF?

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. :)

Creating and using custom JAR in Android project

I am trying to create and use jar file in an Android project under Eclipse. I have tried various methods without any success. Here are the steps:
Create jar file from the source files jar -cf lib.jar *.java
Copy jar file to libs folder
Right click, Build Path->Add to Build path
Now, compiler gives unresolved symbols if I try to use a class from the jar file?
Can someone please let me know correct method to create and use an external jar file for the Android project under eclipse.
This worked fine for me:
1)Place Jars in assets folder.
2)Right click on project name.
3)Select properties.
4)Select Java build path.
5) Select Libraries.
6) Click Add Jars.

Categories