I have a library beside my main project in an android project.
How can I set compiler to it always compile library first and then compiles my main code?
Currently I have to compile two times on every build.
To Add Library project to Your Project
1.If you have a jar file then place the jar file in the libs folder in your project.
then right click on it and Build Path-->Add to Build Path
2.If you have a library as a project then right click on your Main project
Properties-->Android-->Add then select your library project(make sure here library projects with librariesonly appear)
3.if your library project is not appearing in this list then rigth click on your library project Properties-->Android tick isLibrary option there)
you can cjheck out the image like..
if you want to change the priority of your Library
Right Click on your Project Build path--> Configure Build path --> Order and Export
there you will see your library select your library click on top at the right side
the image is like below.
Related
How do I import a jar in Eclipse?
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. A quick demo here.
The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.
Adding external Jar is not smart in case you want to change the project location in filesystem.
The best way is to add the jar to build path so your project will compile if exported:
Create a folder called lib in your project folder.
copy to this folder all the jar files you need.
Refresh your project in eclipse.
Select all the jar files, then right click on one of them and select Build Path -> Add to Build Path
Two choices:
1/ From the project:
2/ If you have already other jar imported, from the directory "References Libraries":
Both will lead you to this screen where you can mange your libraries:
Here are the steps:
click File > Import. The Import window opens.
Under Select an import source, click J2EE > App Client JAR file.
Click Next.
In the Application Client file field, enter the location and name of the application client JAR file that you want to import. You can click the Browse button to select the JAR file from the file system.
In the Application Client project field, type a new project name or select an application client project from the drop-down list. If you type a new name in this field, the application client project will be created based on the version of the application client JAR file, and it will use the default location.
In the Target runtime drop-down list, select the application server that you want to target for your development. This selection affects the run time settings by modifying the class path entries for the project.
If you want to add the new module to an enterprise application project, select the Add project to an EAR check box and then select an existing enterprise application project from the list or create a new one by clicking New.
Note: If you type a new enterprise application project name, the enterprise application project will be created in the default location with the lowest compatible J2EE version based on the version of the project being created. If you want to specify a different version or a different location for the enterprise application, you must use the New Enterprise Application Project wizard.
Click Finish to import the application client JAR file.
Just a comment on importing jars into Eclipse (plug-in development) projects:
In case you are developing Eclipse plug-ins, it makes sense to use Eclipse's native bundling mechanism instead of just importing the jar into a plug-in project. Eclipse (or better its underlying OSGi runtime, Equinox) uses so-called bundles which contain some more information than plain jars (e.g., version infos, dependencies to other bundles, exported packages; see the MANIFEST.MF file). Because of this information, OSGi bundles can be dynamically loaded/unloaded and there is automatic dependency resolution available in an OSGi/Eclipse runtime. Hence, using OSGi bundles instead of plain jars (contained inside another OSGi bundle) has some advantages.
(BTW: Eclipse plug-ins are the same thing as OSGi bundles.)
There is a good chance that somebody already bundled a certain (3rd party) library as an OSGi bundle. You might want to take a look at the following bundle repositories:
http://www.springsource.com/repository/app/
http://download.eclipse.org/tools/orbit/downloads/
http://www.osgi.org/Repository/HomePage
Eclipse -> Preferences -> Java -> Build Path -> User Libraries -> New(Name it) -> Add external Jars
(I recommend dragging your new libraries into the eclipse folder before any of these steps to keep everything together, that way if you reinstall Eclipse or your OS you won't have to rwlink anything except the JDK) Now select the jar files you want. Click OK.
Right click on your project and choose Build Path -> Add Library
FYI just code and then right click and Source->Organize Imports
Jar File in the system path is:
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
ojdbc14.jar(it's jar file)
To import jar file in your Eclipse IDE, follow the steps given below.
Right-click on your project
Select Build Path
Click on Configure Build Path
Click on Libraries, select Modulepath and select Add External JARs
Select the jar file from the required folder
Click and Apply and Ok
first of all you will go to your project what you are created
and next right click in your mouse and select properties in the bottom
and select build in path in the left corner and add external jar file add click apply .that's it
In eclipse I included a compressed jar file i.e. zip file. Eclipse allowed me to add this zip file as an external jar but when I tried to access the classes in the jar they weren't showing up.
After a lot of trial and error I found that using a zip format doesn't work. When I added a jar file then it worked for me.
Right Click on the Project.
Click on Build Path.
Click On Configure Build Path.
Under Libraries, Click on Add Jar or Add External Jar.
If you are having a trouble on udemy course of chad on springboot for the importing the jar. Then follow these steps.
Right click on the project.
You will see a option of Build Path, click on it.
You will have a option of Configure Build path, click on it.
Go to libraries.
Then go to the place where you have a jar files make them into a new folder and upload on a new place.
Then click on Add External Jars, you will surely be able to upload it which will help on classpathxmlapplicationcontext as well.
Thank you.
I have an android project that consist of .jar file's library and some library project's that have not any gradle file's, when i import this project in Android studio i faced to some error's that tell me this librarie's are not applied how can solve this problem?
To add a Jar Dependency in Android Studio. put that jar file in Your project-->app-->libs folder. and then follow these steps
Go to File --> Project Structure
On the left hand side you will see app module. click on that and then on the right hand side select Dependencies tab
Now click (+) button on the right
Select file dependency
A dialog will appear that let you choose your jar file
select the jar you want to add and click ok. DONE
You need to make sure all your modules that have the support library as dependency also have the compile SDK set to 21 . So go to Project Structure and check all the modules on the left hand side.
I downloaded a java/android library .zip file and extracted it. Then I used the command
$jar -cvf java-lib-name.jar topfile/
and it seemed to traverse the folder and create the jar. However, when I then move the .jar into the /libs/ folder, the icons for the packages in the jar are white instead of brown and I can't access them. When I went into Properties->Java Build Path, the .jar is in the Private Libararies section. Did I create the jar incorrectly? Is there another setting in Eclipse I need to use?
You need to compile java classes before creating jar.
Or another thing you can do for this project is to import the library as android library project to your current eclipse workspace and then use it on your android project.
Add the library project using File > Import > Existing Android Code Into Workspace. Make sure this project is marked as a library. Right click on your project, choose Properties, click on Android in left pane > Under library heading, add the library project
I have 2 Java projects in my Eclipse workspace, as follows:
One is a library of code that automatically creates a .jar file whenever it builds.
The other is an application that uses classes in that library, and references the .jar file created by the library project (by right-clicking the app -> Build Path -> Configure Build Path -> Libraries -> Add JARs...)
However, whenever I modify classes in my library project, although I can see that the library .jar gets updated, the app project doesn't pick up the changes unless I remove the library .jar from the app's referenced libraries and re-add it
Am I fundamentally doing something wrong? Is there perhaps a better way to connect an app to a shared library of code? How can I make sure my app will always refer to the latest library code?
Instead of adding it as a JAR dependency you could add it as a project dependency. Right click your project and go to properties. Click on 'Java Build Path' and select the 'Projects' tab. Click 'Add..." and add your library project.
With the latest Eclipse (I'm sure it also worked the same with the ones before), doing a refresh and Clean on your library project then on your application will update the libraries referenced.
In my project, I need to use external library. That library consists of .class files. I have added folder with this library to my project using properties -> Java Build Path -> Libraries -> Add class folder. I can compile project without any problem, but when I run it, I get failed resolving xy and debugger stops on line where I create instance of class from imported files.
I guess the external library I use isnt linked to my .apk file. How can I fix this? I have tried to check this library on "Order and Export" tab assuming that, it will export the library with my application. But it didnt work.
How can I link this library to my project .apk? Do I need to somehow install this library on device first? Do I need to copy this library in application folder?
PS: I'm using Eclipse Juno, android SDK target 10.
Thank you
UPDATE
I have this library copied in libs folder. External library path is:
my_project/libs/sk/aicit/leg/libraries*.class
I have added ./libs folder in Libraries settings of project.
I do not have .jar version of this library, only .class files.
I have also souce code of this library, but I didnt want to include its classes in my project, it has its own dependencies, I wanted to just "link" it like library. Its an external library I havent written.
UPDATE 2
I have copied all the source files from library to my projects "src/" dir. I have removed Library from Java build path. I can stil compile my project, but when I run it Iget
FATAL EXCEPTION:main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{
com.example/myvideorecord/com.example.myvideorecord.Robot}: java.langNullPointerException
...
What can I do, how to debug this error? :(
steps
Copy the library file into libs folder
select jar file -> right click -> Build Path -> Add to Build Path
clean the project Project-> Clean -> select your project -> ok
Android Studio
For importing a Android library into Android Studio, use the following steps:
1) (Optional) I like having my main Android project contain everything it needs to compile correctly, so I move external libraries into the libs/ directory. Generally, you only need to keep the following directories:
res
src
AndroidManifest.xml
*.iml (This will typically be the name of the library you're importing.)
2) Go to your Project Properties.
3) Go to Modules.
4) Import a New Module (Command + N and then Import Module).
5) Navigate to the library directory you want to import.
6) Create module from existing sources.
7) Click Next three times to add the necessary files.
8) Click Finish to complete the module additional.
9) Click on your project in the module list and go to the Dependencies tab.
10) Click the + button at the bottom and click Module Dependency....
11) Make sure your library you're importing is selected and click OK.
12) Click OK in the Project Properties window.
And you should be good to go.
Copy that library file into libs folder
if u have the source code of the library you can import it in eclipse .
Right click on your project -> properties->android -> reference-> add
and add the library project which u have imported. This will include only .class files of the library in ur project