Android: Eclipse jar icons are white and can't access classes - java

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

Related

Eclipse error "the import com.microsoft cannot be resolved" [duplicate]

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.

Android, referencing other libraries

Is there a way, how to add custom library to android app. If I add non-android library to my project it throws error "Only Android project can be add as dependency" and if I reference Android Library to Java Application it throws "This project cannot be added because it does not produce a JAR file using an Ant script." the point is, that I want to keep code on one place (library) and reuse it.
Your best bet is :
1.Create a folder called libs in your project's root folder
2.Copy your JAR files to the libs folder
3.Now right click on the Jar file and then select Build Path > Add to Build Path, which will create a folder called 'Referenced Libraries' within your project

Android & a library project in eclipse

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.

Android import library

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

Questions on how to import google-api-translate-java.jar

I am now going to use the .jar file on http://code.google.com/p/google-api-translate-java/. However, after I download it, I tried to import it in my current project folder (in Eclipse)
the two import statements
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
always get complained by the compiler saying couln't find such class
Could any one help on how to correctly import this .jar file into a project in Eclipse?
You need to add it to your build path. Right-click on the project in Project View, select Build Path->Configure Build Path, then Libraries tab. Now, use one of available options there to add a JAR.
Use "Add JAR" if you copied the jar to your project folder or "Add External JARs" to add it by poiting to a path in filesystem. (Anyway, it is better to copy the jar to the project folder, in which you want to use the jar).
HTH
see How to import class into existing Java project, with Eclipse
Copy the google-api-translate-java-0.92.jar file to your project /WEB-INF/lib/ folder and refresh your project (right click on project and select "refresh").
Google Translate API v1 is deprectaed and will shutdown soon.
You can use Google Translate API v2 Java. It has a core module that you can call from your Java code and also a command line interface module.
Hy I have faced the same issue and fixed it
Step1: download google-translate-api jar file
step2: paste into your app library file
step3: Goto project structure > app > select dependencies -> then add path of your jar file...
Enjoy now you can acess google api services

Categories