Installing additional Java dependencies to react-native library - java

I want to bring more functionality to an existing react-native library - namely to react-native-maps. In order to do that, I have to add an additional Java library. No I wonder where exactly am I supposed to add the Java library. Do I add here (in a newly created lib folder)
https://github.com/react-community/react-native-maps/tree/master/lib/android or somewhere else? How do I make it "known" to Java?

I think you mean with "Java" your IDE. Depends on what IDE you're using if you happen to use
IntelliJ it goes as follows:
Click File from the toolbar
Project Structure (CTRL + SHIFT + ALT + S on Windows/Linux, ⌘ + ; on Mac OS X)
Select Modules at the left panel
Dependencies tab
'+' → JARs or directories
Eclipse
Start Eclipse, and locate the project folder to which the library
should be added.
Right-click this class folder, and select "Properties"
Select "Java Build Path" on the left, and then the "Libraries" tab.
Now, click the "Add External JARS..." button
Locate and select the .jar file you just downloaded, and then
click "Open"
Finally, click "OK" to close the dialog box.
Netbeans
In the Projects window right-click on the name of the project
Click Properties, The Project Properties window opens.
In the categories tree select "Libraries"
On the right side of the Project Properties window press button "Add
JAR/Folder"

In the case of Gradle you should edit the build.gradle file located at the root of the project. In that file under the section dependency.
Copy From Source
Gradle Guide Android Studio 'Adding dependencies'
Local binary dependency
compile fileTree(dir: 'libs', include: ['*.jar'])
Because Gradle reads paths relative to the build.gradle file, this tells the build system to add all JAR files inside your project's module_name/libs/ directory as dependencies.
Alternatively, you specify individual files as follows:
compile files('libs/foo.jar', 'libs/bar.jar')
Example
dependencies {
def googlePlayServicesVersion = rootProject.hasProperty('googlePlayServicesVersion') ? rootProject.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
def androidMapsUtilsVersion = rootProject.hasProperty('androidMapsUtilsVersion') ? rootProject.androidMapsUtilsVersion : DEFAULT_ANDROID_MAPS_UTILS_VERSION
compileOnly "com.facebook.react:react-native:+"
compile files('libs/name_of_library.jar') //<----- added external library for gradle to build
implementation "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
implementation "com.google.maps.android:android-maps-utils:$androidMapsUtilsVersion"
}

Related

Debugging tomcat filter chain in intellij [duplicate]

When creating a new Java project in IntelliJ IDEA, the following directories and files are created:
./projectname.iml
./projectname.ipr
./projectname.iws
./src/
I want to configure IntelliJ IDEA to include my dependency JARs in ./lib/*.jar to the project. What is the correct way to achieve this in IntelliJ IDEA?
Steps for adding external jars in IntelliJ IDEA:
Click File from the toolbar
Select Project Structure option (CTRL + SHIFT + ALT + S on Windows/Linux, ⌘ + ; on Mac OS X)
Select Modules at the left panel
Select Dependencies tab
Select + icon
Select 1 JARs or directories option
IntelliJ IDEA 15 & 2016
File > Project Structure...
or press Ctrl + Alt + Shift + S
Project Settings > Modules > Dependencies > "+" sign > JARs or directories...
Select the jar file and click on OK, then click on another OK button to confirm
You can view the jar file in the "External Libraries" folder
Just copy-paste the .jar under the "libs" folder (or whole "libs" folder), right click on it and select 'Add as library' option from the list. It will do the rest...
If you are building your project with gradle, you just need to add one line to the dependencies in the build.gradle:
buildscript {
...
}
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
and then add the folder to your root project or module:
Then you drop your jars in there and you are good to go :-)
You add them as libraries to your module.
I usually have a /lib directory in my source. I put all the JARs I need there, add /lib as a library, and make it part of my module dependencies.
2018 update: I'm using IntelliJ 2017/2018 now.
I'm fully committed to Maven and Nexus for dependency management.
This is the way the world has gone. Every open source Java project that I know of uses Maven or Gradle. You should, too.
I use this method and it works well:
1- Copy And paste the .jar files under the libs folder.
2- Add compile fileTree(dir: 'libs', include: '*.jar') to dependencies in build.gradle then all the jars in the libs folder will be included..
3- Right click on libs folder and select 'Add as library' option from the list.
Libraries cannot be directly used in any program if not properly added to the project gradle files.
This can easily be done in smart IDEs like inteli J.
1) First as a convention add a folder names 'libs' under your project src file. (this can easily be done using the IDE itself)
2) then copy or add your library file (eg: .jar file) to the folder named 'libs'
3) now you can see the library file inside the libs folder. Now right click on the file and select 'add as library'. And this will fix all the relevant files in your program and library will be directly available for your use.
Please note:
Whenever you are adding libraries to a project, make sure that the project supports the library
Some great help found here. However, I still could not make it to work despite loading JAR properly. I found out later that I accidentally created module in the file structure instead of regular folder and this very module was pre-selected in the project setting.
Here is the footprint:
File -> Project Structure -> Modules -> (select proper module if you have more) -> Dependencies -> + -> JAR or Libraries
While I agree with the previous answers, it's important to note how to access the code of those external libraries.
For example to access a class in the external library, you will want to use the import keyword followed by the external library's name, continued with dot notation until the desired class is reached.
Look at the image below to see how I import CodeGenerationException class from the quickfixj library.
File > Project Structure
Project Settings > Modules > Dependencies (Select one of)
1 JARs or Directories...
2 Library...
3 Module Dependency...
Apply + Ok
Import into java class
You can put the JAR in the libs folder and add it from there. This can be done in 2 different ways in IntelliJ:
Right-click on the libs folder and add from there:
Add the JAR from the project structure:
If you are building your project with maven, you just need to add one line to the dependencies in the pom.xml:
<dependency>
<groupId>com.xxx</groupId>
<artifactId>xxxx-server</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/libs/xxx-server-1.0.0.jar</systemPath>
</dependency>
and then add the folder to your root project or module:
this is my personal experiences. I wish they would help you

How to import a jar package into my IntelliJ [duplicate]

When creating a new Java project in IntelliJ IDEA, the following directories and files are created:
./projectname.iml
./projectname.ipr
./projectname.iws
./src/
I want to configure IntelliJ IDEA to include my dependency JARs in ./lib/*.jar to the project. What is the correct way to achieve this in IntelliJ IDEA?
Steps for adding external jars in IntelliJ IDEA:
Click File from the toolbar
Select Project Structure option (CTRL + SHIFT + ALT + S on Windows/Linux, ⌘ + ; on Mac OS X)
Select Modules at the left panel
Select Dependencies tab
Select + icon
Select 1 JARs or directories option
IntelliJ IDEA 15 & 2016
File > Project Structure...
or press Ctrl + Alt + Shift + S
Project Settings > Modules > Dependencies > "+" sign > JARs or directories...
Select the jar file and click on OK, then click on another OK button to confirm
You can view the jar file in the "External Libraries" folder
Just copy-paste the .jar under the "libs" folder (or whole "libs" folder), right click on it and select 'Add as library' option from the list. It will do the rest...
If you are building your project with gradle, you just need to add one line to the dependencies in the build.gradle:
buildscript {
...
}
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
and then add the folder to your root project or module:
Then you drop your jars in there and you are good to go :-)
You add them as libraries to your module.
I usually have a /lib directory in my source. I put all the JARs I need there, add /lib as a library, and make it part of my module dependencies.
2018 update: I'm using IntelliJ 2017/2018 now.
I'm fully committed to Maven and Nexus for dependency management.
This is the way the world has gone. Every open source Java project that I know of uses Maven or Gradle. You should, too.
I use this method and it works well:
1- Copy And paste the .jar files under the libs folder.
2- Add compile fileTree(dir: 'libs', include: '*.jar') to dependencies in build.gradle then all the jars in the libs folder will be included..
3- Right click on libs folder and select 'Add as library' option from the list.
Libraries cannot be directly used in any program if not properly added to the project gradle files.
This can easily be done in smart IDEs like inteli J.
1) First as a convention add a folder names 'libs' under your project src file. (this can easily be done using the IDE itself)
2) then copy or add your library file (eg: .jar file) to the folder named 'libs'
3) now you can see the library file inside the libs folder. Now right click on the file and select 'add as library'. And this will fix all the relevant files in your program and library will be directly available for your use.
Please note:
Whenever you are adding libraries to a project, make sure that the project supports the library
Some great help found here. However, I still could not make it to work despite loading JAR properly. I found out later that I accidentally created module in the file structure instead of regular folder and this very module was pre-selected in the project setting.
Here is the footprint:
File -> Project Structure -> Modules -> (select proper module if you have more) -> Dependencies -> + -> JAR or Libraries
While I agree with the previous answers, it's important to note how to access the code of those external libraries.
For example to access a class in the external library, you will want to use the import keyword followed by the external library's name, continued with dot notation until the desired class is reached.
Look at the image below to see how I import CodeGenerationException class from the quickfixj library.
File > Project Structure
Project Settings > Modules > Dependencies (Select one of)
1 JARs or Directories...
2 Library...
3 Module Dependency...
Apply + Ok
Import into java class
You can put the JAR in the libs folder and add it from there. This can be done in 2 different ways in IntelliJ:
Right-click on the libs folder and add from there:
Add the JAR from the project structure:
If you are building your project with maven, you just need to add one line to the dependencies in the pom.xml:
<dependency>
<groupId>com.xxx</groupId>
<artifactId>xxxx-server</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/libs/xxx-server-1.0.0.jar</systemPath>
</dependency>
and then add the folder to your root project or module:
this is my personal experiences. I wish they would help you

Adding a library to a netbeans gradle project

I have decided to try and use libgdx for graphics. However it uses gradle to manage the package; I however have very little experience with gradle.
My question is, if I have a library (.jar file) of my code. Normally in netbeans I can right click 'libraries' and choose 'add jar/folder' and it adds the library to my ant file and more importantly the ide now recognizes the .jar and exposes it to the auto-complete etc.
On gradle I have only gotten the file to show up in the 'dependencies' branch by putting the following in the build:
dependencies {
runtime fileTree(dir: 'libs', include: '*.jar')
}
However the libraries won't import, nor does the ide recognize their existence. The (absurdly large) online documentation for gradle seems to only want to deal with repositories and I can not find documentation for netbeans gradle. Any help would be greatly appreciated.
This one stumped me for a while as well...
First manually add the dependency to your build.gradle script. Like your example:
dependencies {
runtime fileTree(dir: 'libs', include: '*.jar')
}
Then, in Netbeans's "Projects" side-panel, right click on the project name and select "Reload project" from the context menu.
Your dependencies should then show up under the project's Dependencies folder, and code completion, compile error checking, etc. should work as usual.
If you cannot see the "Projects" side-panel click select from the menu bar Window -> Projects or press Ctrl + 1.
In netbeans 11 it looks like the reload project option has been moved to right-clicking on 'Configurations' in the projects root folder and selecting 'Download Sources'

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.

Eclipse - Importing your own library

Okay, hopefully this is quick and easy.
I have two separate java projects, 'Library' and 'Project', and I have a class in 'Project' that wants to implement a method found in 'Library'. I am looking for some kind of 'import' call to make at the top of my 'Project' class, to make the methods found in 'Library' accessible in that project.
How would I do that?
On another note, this 'Library' project only exists because I want to use a number of classes of my own to supplement the the usual java libraries (java.util, java.io, etc...). Is there a way I can add my java project to my java libraries? (ie. 'import java.Library.className;')
Thanks,
Jonathan
Just have "Project" reference your "Library", on windows the process is (using menu / tab names)
1. Go to: Project -> Properties -> Java Build Path -> Projects
2. Client Add...
3. Select your "Library" project from the list
4. Click Ok
5. Click the other Ok
Now your done and you can use import for classes in your "Library"
There are several ways:
A. Import source files
Right click your project in the project explorer
select
Properties-->Java Build Path
Click on the Source tab and the Link Source button and add the root folder containing Library and click Finish
Now click on the Projects tab and click the Add button to add your 'Library'. Click Ok and you're done
B. Import Jar
When you compile your eclipse project it creates a jar for your project in the 'Build' subfolder of the root directory of your project. To import that in you current project:
Again Right click your project in the project explorer
Select Properties-->Java build Path
Click on the Libraries tab and click Add External JARs. Navigate to the folder containing Library.jar and click Finish and click Ok
You should now be able to import your names from your Library Project

Categories