PDFbox jar is added in intellij(Setting> Project Structure> Modules> Dependencies) and Have added the gradle dependency as
testCompile 'org.apache.pdfbox:pdfbox:2.0.1'
in gradle build and the build is successful.Even after this importing 'import org.pdfbox...' in java file shows error as cannot resolve symbol pdfbox.
Also tried File->Invalidate Caches\Restart.
Sometimes, you don't need to open the Project Structure dialog to create a library and add it to dependencies of a module. This is the case when there are .jar files within your project content roots.
You can select such .jar files in the Project tool window and use these files to create a library. When doing so, you will be able to select the library level and the module to whose dependencies the new library should be added.
In a similar way, you can use a directory containing .jar files to create a library.
Open the Project tool window (e.g. View | Tool Windows | Project).
Select the .jar file or files to be included in the library, or a directory that contains the .jar files of interest.
Select Add as Library from the context menu.
In the Create Library dialog, specify the library name, level and the module in which this library will be used.
This solved the issue.
Related
I'm trying to make use of a jReddit library, which, in turn requires apache HttpComponents and Commons IO libraries.
I downloaded the sources, added them in Itellij Idea through File - Project Structure - Modules - Add Content Root.
All the classes from the libraries that my code makes use of are imported successfully. But the problem appears when compiling - it says that package com.github.jreddit.oauth does not exist and package org.apache.http.impl.client does not exist and that it cannot find symbol of those libraries' classes.
Why does this happen and how to fix it?
Don't use Maven or Gradle if you can't even manage adding a JAR to your project manually.
You should acquire those JARs (containing .class byte code files, not .java source), add them a folder in your project named /lib, and add that directory as a JAR source location in your project. They'll be in the CLASSPATH then.
You need to add the /lib folder to an artifact when you run. Be sure you know how to do that as well.
I ran into this error after upgrading IntelliJ to version 2019.1. These steps fixed it for me:
Click Run from the toolbar
Choose Edit Configurations
Make sure the Scratch file you want to run is selected on the left panel
In Use classpath of module dropdown, select the project module that contains the proper module
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.
People say they are the same but they are used in different situations as said in developer site
1-Adding libraries without resources
To add a Support Library without resources to your application project:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
2-Adding libraries with resources
To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
Right-click the library project folder and select Build Path > Configure Build Path.
In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects.
when should I use appcompat_v7 (which is generated with the project automatically )
and when to use android-support-v7-appcompat ?
In which case the programmer needs to add library with the resources in the project ?
please feed me with your experience
android-support-v7-appcompat.jar is a JAR file, containing only compiled Java classes. appcompat_v7 is a Library Project, which contains the previous JAR file, no actual source code, and a great many resources (layouts, images, &c).
In the particular case of appcompat-v7, you need to use the Library Project, since it contains necessary UI resources.
Other libraries (such as v7 MediaRouter or v7 Palette) do not contain these resources, and therefore the JAR file can be used directly.
Note that the difference applies mainly to Eclipse (in which libraries with resources must be imported as a project while the others can be just placed in the libs folder). With Android Studio/gradle this is all handled by the build system and therefore the procedure is the same for both. This is well explained in the Support Library Setup documentation.
The generated appcompat_v7 contains the android-support-v7-appcompat library, along with some resources. If you let Eclipse generate your themes and layouts, they will refer to the resources in the appcompat_v7 project and your project won't build without it. I've never encountered a situation where I needed only the library without the resources, but perhaps you might if you wanted to incorporate a new support library feature into an existing project.
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
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