How to use your own created jar file in another android application - java

I created my own jar file using eclipse. Now i am trying to make an android JAR file and then will use the same JAR file in others android apps.
Now though, my application is complete and make a jar file, but how i will use it for other Android Apps?

You should be able to access any publicly exposed methods from your .jar by importing the .jar into your project, then adding
import myjar.myclass;
You can then reference any methods from the class you import.
Hope this helps!

Add the jar to you build path
Right click project
Click "Properties" -> "Java Build Path" -> "Libraries"
Click "Add External Jar"
Import classes like normal
import com.my.package.here.MyClass;

Related

Use classes in jar file in java program in eclipse

I have converted my java code into .jar now i want to use the class in that jar file in another class, so i am unable to do so. Thank you very much for any kind of help!
In Eclipse, right click on your project where you want to use your jar. Select "Properties", there select "Java Build Path". Under "Libraries" you can add the JAR (if you copied it to a lib folder in your project), or select an external JAR (if you don't have it in your lib folder).
When this is done, you can use it in your code. Just use the class, and when a red scribble is underlining your class name, hover over it and select "Import 'Classname' (this.is.your.package)". Alternately, you can let Eclipse auto import the most logical package by pressing "CTRL+Shift+O" (hotkey to auto import)
Add the jar in the new project classpath and then you should be able to use the classes.

Importing class/java files in Eclipse

I'm new to Java Programming using Eclipse, so would really appreciate your help for this question.
I have doing Java programming both at college and home. At home, I have all my Java classes under a single project-(Java Reference). Now, in college, the java programs are compiled on the lab machines. And I would really like to have all these programs in a single project, on my laptop.
I had recently copied all the .class and .java files from the programs we did in college labs, so I could have them under the "Java Reference" project in my laptop. I copied the .class and .java files under the "bin" and "src" folders of the java project, on my laptop. However, I don't see anyway to import them through Eclipse.
From what I read here, it looks like having an entire project(created somewhere else) could be copied into one place, through the import option, but in my case, I only have the .class and .java files.
First, you don't need the .class files if they are compiled from your .java classes.
To import your files, you need to create an empty Java project. They you either import them one by one (New -> File -> Advanced -> Link file) or directly copy them into their corresponding folder/package and refresh the project.
You can import a bunch of .java files to your existing project without creating a new project. Here are the steps:
Right-click on the Default Package in the Project Manager pane
underneath your project and choose Import
An Import Wizard window will display. Choose File system and select the Next button
You are now prompted to choose a file
Simply browse your folder with .java files in it
Select desired .java files
Click on Finish to finish the import wizard
Check the following webpage for more information:
http://people.cs.uchicago.edu/~kaharris/10200/tutorials/eclipse/Step_04.html
create a new java project in Eclipse and copy .java files to its src directory, if you don't know where those source files should be placed, right click on the root of the project and choose new->class to create a test class and see where its .java file is placed, then put other files with it, in the same directory, you may have to adjust the package in those source files according to the new project directory structure.
if you use external libraries in your code, you have two options: either copy / download jar files or use maven if you use maven you'll have to create the project at maven project in the first place, creating java projects as maven projects are the way to go anyway but that's for another post...
I had the same problem. But What I did is I imported the .java files and then I went to Search->File-> and then changed the package name to whatever package it should belong in this way I fixed a lot of java files which otherwise would require to go to every file and change them manually.
import class folder does not work for me, but add jar worked!
1. put the class folder under the project folder
2. Zip the class folder
3. Highlight project name, click "Project" in the top toolbar, click "Properties", click "Libraries" tab, click "Add External jars".
4. Add the zip file. Done!

How do I deploy a Java program in Eclipse?

I have a program I am making for a friend. It contains one class, references two libraries (sqlite4java and poi by Apache), and sqlite4java contains many native libraries (.so, .dll, .jnilib) that are within my lib folder. The program also reads and writes from a swimTeam.db file.
My question is how do I package this all into one program that can be run cross-platform? I have tried exporting the project as a runnable jar, but when I ran it it couldn't access the native libraries because they weren't exported. Any idea how to do this?
First thing is create a java project remove all the java files and copy all the Jar file you need to import into that project.
now add the the created project to your working project as "project references" (right click on the project and click on properties)
now add all the Jars in the Java buildpath->libraries
now export your project as JAR. open it and make sure that all the JARs u need are in it.

how to import a java class by a jar file

I had a problem when importing org.slf4j.Logger and org.slf4j.LoggerFactory, how to download these two classes and if it is by the mean of a jar file, how to import from it.
To be able import any classes into your project, such classes should be added to the classpath of your application.
Usually you won't need to extract classes from library, so in your case you need to add slf4j-api-1.7.5.jar from slf4j-1.7.5.zip which accessible here: http://www.slf4j.org/download.html
Here you can find example how to add library for eclipse project: http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29
If you do have the corresponding Jar file, you just have to add it to your project. If you are using Eclipse IDE, you can click on "Project" menu, "Properties", "Java Build Path", "Add External Jars..." and then a file chooser will appear. Choose the location of your Jar file and open it. Here you go. If you are using another IDE, just specify it, so we can further help you with respect to your IDE.

how to import own jar into android project (ADT 20)

If I import a selfmade jar file into my Android project (add it to the libs folder) I get an "Could not find class" error sent by dalvikvm. (I'm using Eclipse)
Obviously it's not an import error, because downloaded jars (like jdome) worke fine.
So I guess it's an export error. The way how I export a jar is: right click on project -> export -> jar -> leave default settings -> finish
I'm sure it's no internal problem, because the jar contains only one class which has only one method for test reasons.
Does anyone know what I did wrong?????
Just copy and paste your .jar file in libs folder of your project.
Yry this, I hope this will work for you:
Go To Your Project
Right Click
Properties
Java Build Path
Libraries
Add External Jar
Select Jar File
OK

Categories

Resources