How to import a Java library in Eclipse? - java

I have downloaded and am trying to import this library: https://github.com/sachin-handiekar/jInstagram in one of my projects. However, whenever I point to the directory where this project is located and try to import it, Eclipse says "No projects are found to import." I even tried importing it as Android code but it didn't recognize it either. How do I import and use this library in my Android project?

Just to use this library within your project add it as a Maven dependency
<dependency>
<groupId>com.sachinhandiekar</groupId>
<artifactId>jInstagram</artifactId>
<version>1.0.9</version>
</dependency>
If you don't know how to do this check this plugin: maven-android-plugin
You can also checkout the complete source tree for the project and then go to the directory containing the pom.xml file and using Maven run mvn install to build this project and then import it to the Eclipse.

It says no projects are found to import because it is looking for the eclipse .project file which is not included in git repositories. Try the import file system option
Or better yet, try out the git plugin for eclipse

Its easy, in Activity press Ctrl + Shift + O

Related

Java project issue in import

I am very new to java.
I downloaded Netbeans 8.2 and Jdk 1.8 and installed both.
And opened one of the projects where I'm getting three import statement issue.
import org.apache.commons.fileupload;
import org.apache.commons.fileupload.disk.diskfileitrmfactory;
import org.apache.commons.fileupload.servlet.servletfileupload;
I have my got the below jar in web-inf/lib path in project
Commons-fileupload-1.2.2.jar
Commons-up-2.4.jar
Please guide me to get the project compiled. I am clueless since I have no idea about java and trying to run the project and debug .
Import your jar files the proper way.
Right click your project >
Properties >
Libraries
Then click the Add Jar/Folder button to import the jars you need.
After this, clean and build the project (Right click > Clean and Build), and try to run it.
Your setup probably has some sort of error to find out the path to those .jar files, it is common to happen when you've got the files imported in a wrong way.
I'd like to suggest to you to use Maven. Maven is a dependency manager and will be in charge to manage all your dependencies along the build of your project among all other features. It is easy to use and will make your life a lot easier.
Here you have two links, one if you'd like to understand better how it works (https://maven.apache.org/guides/getting-started/) and the another to help you to build your Maven project (https://maven.apache.org/guides/getting-started/). I don't use NetBeans IDE but it probably has support for Maven, but in case it doesn't, you could look for a plugin.
Hope it helps.

Is it possible to import a Maven JAR in a regular Java project?

Is it possible to import a Maven JAR in a regular Java project?
If yes how to do so. I am using Eclipse Neon IDE.
Yes it is absolutely possible to import local maven repository's jar in your simple java project in eclipse.
Since maven download jars in local repository which is on your computer (in general) .So you can use those jars as you normally use downloaded jars from other location in your computer.
To know maven repository location from eclipse
Click on window->preference ->type maven in search->user setting -> you will Local Repository
as shown in below snap shot

How can I import javax.json in eclipse

I have installed eclipse ide for EE developers and I am receiving an import error for
import javax.json.Json;
import javax.json.JsonReader;
etc.
I have right clicked on project folder -> clicked properties -> clicked Java build path -> add library -> JRE System Library,
but the dependencies that show up are already imported. How can I import the javax.json package?
If using Maven, add this dependency to your pom.xml
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
For Gradle, add this to your build.gradle
compile 'javax.json:javax.json-api:1.0'
Going to assume that you are not using Java 7 and thus need to add the JAR file directly to your project path:
Here's the link to the
JAR
And where it came from:
http://jsonp.java.net/
Download and add to your project build path.
You need to get a hold of the Jar from https://java.net/projects/jsonp/
Then got to project folder -> clicked properties -> clicked Java build path -> Add External Jars...
From here you can import the downloaded Jar (library) into your project.
Using javax.json group (what is in the accepted version) doesn't work for me. I get this:
javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
Instead, what does work for me is the following (put this in the dependencies section of build.gradle if you're using Gradle):
implementation "org.glassfish:javax.json:1.1.4"
To find the latest version of the library, see the library's search.maven.org page.
You will have to download the Jar from https://java.net/projects/jsonp/ as they are not yet part of main Java runtime, download the jar and add it to your classpath and it should work
JSR http://jcp.org/en/jsr/detail?id=353

Importing a Java project to IntelliJ IDEA community edition

I'm new to IntelliJ. What is the best (and recommend method) for importing project into IntelliJ. Is there a maven plugin for doing this?
More specially I'm interesting in importing this project.
https://github.com/nathanmarz/storm-starter?source=c
Thanks.
UPDATE 1 - When I try to use File -> open (the m2-pom.xml file) it just opens the xml file (as shown in the screenshot below.
It looks like that project has a pom file named m2-pom.xml. You should import that as a maven project. Assuming it's using standard repositories, you'll immediately be able to compile the code with maven.
You can select Open in the menu, and then choose that file and it should load the project.
Be aware this seems to be a clojure project. You might want to research the La Clojure plugin to see how/if it can import clojure projects with it. It looks like the steps I gave will work, but the code may not run very easily for you without the La Clojure plugin.
You could either import the Maven project inside of IntelliJ (File -> Import Project...), or you could simply use the Maven IDEA plugin. All you do is execute mvn idea:idea inside of the Maven directory, and a project file will be generated. This file may be opened as a project inside of IntelliJ.
EDIT: #maba warns not to use the Maven IntelliJ plugin.

Making Eclipse Recognize Imports

I am trying to integrate Spring into my project in Eclipse. I am using Maven and have added the dependencies in my POM. While the maven build works, Eclipse does not recognize imports like the following.
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
How do I get Eclipse to recognize Spring imports? I am hoping there is a way to do this w/o downloading the jar files, etc.
Thanks in advance.
Eclipse doesn't support Maven projects natively. You must install a plugin (m2eclipse) to be able to use a Maven project inside Eclipse.
Another way to fix this is to open a command line, navigate to your project, and run mvn clean install and/or mvn eclipse:eclipse the first will parse the pom.xml and download all the dependencies and the second will build your eclipse meta-data files(.classpath and .project) you can even do this with the project open in eclipse and hit F5 to refresh and viola
Check your maven path in eclipse.
Window >>> Preferences >>> Maven >>> User Settings
Check for User Settings field that contains settings.xml

Categories