Build java library with resources - java

I am trying to make android java library, but when I build my project in output jar library placed only java compiled classes, but no resources and assets.
Also my project contains native libraries, I need to include it in jar too.
PS: I have connect my library project to another project.
PS2: I have find out that resources from library project (res, libs) compiles into apk file, but assets not. How to make assets compile too?

To export jar with resource file please follow the below steps.
1) Right Click on Project Folder
2) Then Click on Export
3) Click on Java -> Jar file.
4) It opens a Jar Export Dialog . Please ensure that Exported generated class file and
resource check-box is checked.
5) Then provide the export destination .
6) Finally click on finish button.

In export menu for eclipse, you have a check box asking you for the inclusion of source files

Related

How to link an external jar file in two java projects

ok guys, I'm trying to import the jfugue android port library into a libdx project, but I don't know how to add the jar files from the core project to the android one, since they don't appear as jar in the add jar option in the android build path project.
The jar file you're pointing to is an external jar (you can see it has a full path), so add to the other project using "Add External JARs" button on the "Libraries" tab of the "Java Build Path" page of the project's properties dialog.
Step-1>Just copy the jar files from Quintas_analizer project and paste
them in libs folder of Quintas_analizer-android. Then right click on
the jar files in Quintas_analizer-android and add to build path.
or
Step-1.1 >Another way is that-> right click Quintas_analizer-android
->properties-> Android->Add-> Select the project Quintas_analizer and add.
If Quintas_analizer not shown then go to Quintas_analizer ->
properties -> Android-> Mark the checkbox ->is a library-> Repeat step
1.1

Android external Jar

I have some api with java and I need it in my android app.
When I am using it with including all packages and classes it works fine. Now I create JAR file from my java project using export. Now when I add the jar to my android app as a external jar my all errors are disappeared but when I run my app I got an error
java.lang.NoClassDefFoundError.
I have seen that kind of errors early in my apps and it was the problem of Jar. How can I generate JAR file to avoid this situation?
You have probably built that jar file with jdk 1.7. Classes compiled with jdk 1.7 are not included in apk file. Try to change java compiler to 1.6 before you export jar. In eclipse go to Window -> Preferences -> Java -> Compiler.
copy the jar file in the libs folder of your android project.
After that you may want to clean your project and rebuild it. You can even clear manually the bin dir content.
You have to add your jar file to your project's buildpath.
To make sure it's exported in your APK, you also have to check it under the Order and Export tab, in the build path preferences of your project.
A better approach might be the following:
remove the current exported jar from your project
select the project you want to import, right click -> properties -> android -> check 'mark as library'
right click your current project -> properties -> android -> locate the 'add' button in the bottom. Click it and select the library project.
Using this approach any changes in the library project will be reflected in your current project (at least after doing a clean projects).
I have done it !!! Thanks everybody.
So the solution is :
1. change java compiler to 1.6 before you export jar (As #Lecho mentioned)
2. Move the Jar file to lib folder
So it works !!! thanks everybody

How to use *.jar file in a Java project?

I'm a complete novice to Java, and I'm stuck in trying to use an external jar library in a Java project I'm working on.
The library is Twitter4J (http://twitter4j.org/), a complex group of files which I can't understand how to include. I'm using Eclipse on Windows. I understood the meaning of CLASSPATH enviroment variable (or well, I think I did), but I can't understand how to link it to the Eclipse enviroment.
This blog post seemed to be what I was looking for: http://jasperpeilee.wordpress.com/2012/01/25/how-to-set-up-twitter4j-quickly-in-your-java-project/
But:
Add twitter4j-core-2.2.5.jar into project for general use.
1) Where should I copy the core file? In the /bin/ folder? Or in a completly unrelated /lib/ folder, as this question in SO stated?
Copy Twitter API property file into your project/bin directory.
2) What is the Twitter API property file?
3) How can I include JavaDoc jar files too? Is it possibile to get them into Elipse?
Any kind of help, even just a link, will be very appreciated!
You probably have a project folder for your Eclipse project. Go ahead and make a lib folder inside of your project folder, in the same directory as src and bin. There's nothing special about the lib folder specifically, it's just a convenient name. Copy the .jar file into your newly created folder. Back in Eclipse, right click your project and click Refresh. The lib folder should pop up, including your JAR! Right click the JAR file and go to Build Path --> Add To Build Path. At this point, any class in the project should be able to use Twitter4J features.
As for the What question, the Twitter API property file contains configuration that is necessary for the Twitter jar to function. The file should probably be located on the classpath of your application.
And the How question, you can attach the javadoc jar file of the Twitter jar to the Twitter jar's classpath entry in Eclipse. Right-click your project and select Properties. Go to the Java Build Path entry and find the Twitter jar under the Libraries tab. If you expand the Twitter jar entry you will see 'JavaDoc location'. You can specify the javadoc jar there.
In Eclipse, right-click your project, select Properties. Now find the entry for Java Build Path and select it. Click the "Libraries" tab if it is not already selected. Click the "Add external JARs..." button. Follow the prompts.

unable to install common codec jar file

I have downloaded common.codec binary jar file. Now I want to use the class org.apache.commons.codec.binary.Base64. But this folder contains four jar files namely common.codec-1.7.jar,commons-codec-1.7-javadoc.jar, commons-codec-1.7-sources,commons-codec-1.7-tests,commons-codec-1a.7-test-sources. Now which path should I mention in class path? And I tried with all the jar file paths and imported in my program but failed. Please tell me where to place this downloaded jar file and how to use it in my code.
You can use common.codec-1.7.jar if you are using an IDE like
Eclipse:
1.Right-click your Project.
2.Select Properties.
3.On the left-hand side click java build path.
4.Under Compile tab - click Add External Jars button.
Netbeans :
1.Right-click your Project.
2.Select Properties.
3.On the left-hand side click Libraries.
4.Under Compile tab - click Add Jar/Folder button.
or if you directly compiling classes without IDE you can do as #S.R.I mentioned in comment.

Exporting android project to jar (that includes other jars)

I've written a Android Game Engine library and would like to export it to a jar file. I've tried to do this with the following:
export > Jar File > Finish
As soon as I add the jar to the build path of another Android project, I get a little box in my code saying:
The type foo cannot be resolved. It is indirectly
referenced from required .class files
I believe this is because my Game Engine library includes other libraries in forms of jars.
How can I add those jar files to my Game Engine jar file?
You can decompile the other jar file using JDui, take what you need, and add it to your library. It all depends on how big is what you need..
Also, check whether you are using proguard in the export. You would have to be careful on how to configure it.
I assuming you are using Eclipse. You also need to use Properties->Java Build Path->Libraries->Add Jar button to add your jar file to the target project

Categories

Resources