i have a requirement like i have to use one app for two other applications. so i want to create a library project as jar file so that i can use that in build path easily with out adding the project. so i have added my main project as a library project so it has generated jar file in bin folder . so i have copied that jar file and added to libs and added that to my project build path. but still i am getting no class def found exception. please sugest whether this process of generating a jar file is correct or not. if it is not correct please suggest me how to do.
Rightclick on the library project, export -> Jar file.
Select all files, except the AndroidManifest.xml.
Make sure you DON'T select manifest file. Else it will lead to conflict errors.
Now include this JAR file in the build path, and it will work. I did the same.
Let me know if you have any issues.
The Most Important thing , your project doesn't contain any Resources (RES folder) then
1- Right Click on Project –> Export —> Java –> JarFile
2-Select only the src checkbox ie the (pacakages) in Top-Left Window.
Don’t Select anything in Top-Right Window if some thing is selected remove marks .
3-Select Only Export generates Class Files and Resources
4-In Options Select only Compress the contents of the jar file (it's not important)
To add your External Jar to Your File
1-Right click on project –> Select Properties –> Java Build Path —> libraries –> Add External Jar Files –> Click OK
2-CLEAN your Project
You can export your project as a jar.To do this
right click your project->export->java->JAR file->Next
But if you use resources in the library project then you won't get it from the jar.But it will be available if you use as a library project rather than jar
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.
Source
You need to do following:
Add reference of .jar file to your client application. Right click project -> properties -> Click 'Java Build Path' -> open Libraries tab -> Click button 'Add External JARs..' and select the .Jar file that you have created -> Go to 'Order and Export' tab and select the Added external Jar and move it to the top.
I hope this will help you.
Mark +1 if it is helpful to you.
Related
I make an android library project. It has some jar files and .so files.
I export this project as jar file
File->export->jar file->check my project with all folders and files,
uncheck AndroidManifest.xml,
check Export all output folders for check project
check Export java source files and resources
-> finish.
But when I add to my another project(libs folder) and add this on javaBuildPath, after run in the log cat show "NoClassDefFound Error (one of the jar file)".
How can I fix this problem?
Edit: I'm using Eclipse IDE
Please follow the steps:
1- Right Click on Project –> Export —> Java –> JarFile
2-Select only the src checkbox ie the (pacakages) in Top-Left Window. Don’t Select anything in Top-Right Window if some thing is selected remove marks .
3-Select Only Export generates Class Files and Resources
4-In Options Select only Compress the contents of the jar file (it's not important)
To add your External Jar to Your File
1-Right click on project –> Select Properties –> Java Build Path —> libraries –> Add External Jar Files –> Click OK
2-CLEAN your Project
Must clean and build.
I am trying to compile a java project which makes uses of android libraries. The project I am using is checked out from a svn repository.
In order to take a use of that project I am required to define some jar files and libraries for that project.
Here are the files that I need to make sure they are defined:
•"lib/apache-mime4j-0.4.jar" : Jar
•"lib/httpmime-4.0-beta1.jar" : Jar
•"lib/slf4j-android-1.5.8.jar" : Jar
•"JUnit 4.libraryclasspath" : Library
•"ANDROID_SDK_PLATFORM/android.jar" : var
•"Java JRE System Library" : Library
Does anyone have any idea about what should I do to define these files? I am a noob here.I do not know which selection should I choose When I clicked "project -> properties -> java build path -> libraries"
For example if I want to define the first jar file, there are a "add external jar" and a "add libraries" selections.
However you can see a "lib" here in front of the "apache-mime4j0.4.jar file" in this list above..
So I don't understand if it is asking me to add a jar file or the librabry.. I am getting very confused about this.
And also How can I do anything with "JUnit 4.libraryclasspath" file? I think it is a classpath file so I cannot either choose "add jar files" or "add libraries" to define it..
Hope someone has any knowledge about this and I will be very appreciated!
I think You are unable to include the files due to SVN path but will discuss it later.At first we look how to add jar files
Right click on your project in which you want to add the jars
1.select build path and then "configure build path"
2.click on "Libraries" tab
3.Now click on Add external jars (as your all jars files would be placed in some directory outside the project folder or anywhere else)
4.Select these jars and now do OK ... Now these jars are in your class path and you can use these files.
Now another thing, As You told that you are using svn , It means many of other developers are also using the same project then it is compulsory that all of you have same path of jars in your systems for instance in Dev1 PC the jar if the jar file is placed in d:/lib/jars folder then all other DEV2 , DEV3 ... DEVn must have d:/lib/jars folder and their jars must be placed there and you have to add these jars from d:/libs/jars
Last thing , If you are still unable to understand the solution and remove the bugs then simply do this.
Copy all jar files manually (ctrl+c) and copy to lib folder in your project as i have seen that in your project the person who commits the code place them there.
after then , right click on your project and click refresh(as it is bad practice to put jar files in project by creating folder like lib etc unless it is a web project)
Let me know if anything is unclear about this
I deleted a jar from my libs file and now I cannot build the project and the jar will not go away.
I've tried cleaning the project, fixing the android properties now I'm stuck.
Has anyone else had this problem?
Description Resource Path Location Type
Archive for required library: 'C:/apps/APP/libs/imagecrop.jar' in project 'APP' cannot be read or is not a valid ZIP file APP Build path Build Path Problem
Solution.
Don't use clean or "fix project properties"
Simply right click on the project and press "Refresh"..
You need to remove it from your build path. Right click your project, go to Properties->Build Path. The build path contains four tabs:
The Java Build Path properties page contains four tabs:
Source. The source and output folders. If you initially create a project without separate source and output folders, you can change it here. Multiple source folders can be used in one project; e.g., to separate application source code from unit tests.
Projects. Check-off other projects in the workspace whose output folders should be added to this build path.
Libraries. Location of other archive files required by this project.
Order and Export. Order in which projects and libraries appear in the build path and the default runtime classpath; e.g., use classes from a workspace project before using the same classes from an archive library.
Go to libraries tab and remove the jar file you deleted.
Also refresh your project by right click -> Refresh so it will realize you deleted jar file.
I have created a library project which can be used as reference project in any application.
Now i want to create jar file of that library project so that instead of referencing the library project,i can add that created external jar file to build path and can use the library project component.Is there any way in eclipse to do so???
JAR file using Eclipse IDE
Creating JAR file using Eclipse IDE is pretty much easy. Follow the simple steps.
Right click on your project, which you want to create a JAR file of. And select Export from the context menu.
Select JAR file from Java folder and click Next.
Provide the Destination path and click on Finish to create the JAR.
Here how to add JAR to your project, you can also create libs folder and drag an drop your jar inside this folder
You will need to export that project in eclipse. here are the steps:
1) right click the project in project explorer view.
2) click on exprot and type jar.
3) select the jar option and by giving appropriate name click on export.
The jar file will be created which u can use by adding it in the build path of another project.
yes, You can do it in Eclipse...
//Exporting project to jar file
Right Click the desired project->Export the project->Choose java->jarFile->Select the project to the export and choose the destination for the jar file to be saved->Click finish-> jar file will be created in desired destination
//Including jar file
Again Right Click the project(where jar file to be included)->Choose Properties->Select the java build path->add External jar->choose the jar file->jar file will be included.
I saw an article about including additional javax.* packages in your Android App
http://code.google.com/p/dalvik/wiki/JavaxPackages.
I wanted to do the same thing, but using Eclipse.
Could anyone help me figure out how to do this?
Step 1: Properties -> Java Build Path -> Libraries -> add external jar
Step 2: Properties -> Java Build Path -> Order and Export -> check the new lib
Adding an External Library (.jar) using Eclipse
You can use a third party JAR in your application by adding it to your Eclipse project as follows:
In the Package Explorer panel, right-click on your project and select Properties.
Select Java Build Path, then the tab Libraries.
Press the Add External JARs... button and select the JAR file.
Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead. It is not necessary to put external JARs in the assets folder.