maven can not import jar in mac osx - java

I build a common maven module named push-common. Another project need to import it. The one who use windows system can import it with maven dependency. However, the one who use Mac can't import it. The pom.xml configration as follows
<dependency>
<groupId>com.llh</groupId>
<artifactId>push-common</artifactId>
<version>1.0</version>
</dependency>
In actually, the push-common-1.0.jar even have been downloaded in local maven repository, but just can't import to project. By the way , the IDE is intellij idea 14.

Build the project with mvn clean install, it will help you

Related

intellij idea cannot import local jars in local repository which I just installed by maven install

I am new to intellij idea and I was blocked in the bulid-process. I get two springcloud based projects and I have installed the so called 'scp-accesscontrol-component-client' in one workplace and I have found the installed jar in local repository. But the other project dependency cannot import the jar from local repository but download from the remote repository and it cannot find the jar for I haven't deploy into the remote reposite. How to set IDEA to aotu-import bulit-jars from the local repository?thanks!
When you are using maven, you can add it to the pom.xml file as a dependency. Then IDE will get the jar automatically when running the maven command.
<dependencies>
<dependency>
<groupId>com.abccompany</groupId>
<artifactId>sample-app</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>

IntelliJ Idea not resolving Mockito and JUnit dependencies with Maven

I am using IntelliJ idea for writing simple unit test cases using JUnit and Mockito. I am using Maven for dependency management.
IntelliJ idea keeps complaining that following imports cannot be resolved:
import org.junit.Test; //Cannot resolve symbol 'Test'
import static org.mockito.Mockito.*; //Cannot resolve symbol 'mockito'
Following is the dependencies section of my project:
<dependencies>
<!-- Dependency for JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<!--<scope>test</scope>-->
</dependency>
<!-- Dependency for Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<!--<scope>test</scope>-->
</dependency>
</dependencies>
Following is my project structure:
Try View -> Tool Windows -> Maven projects, then click the blue icon in the top left of the tool window (Reimport all Maven projects). You should be able to find the dependencies in the project view, under external libraries.
If this does not work, there is probably something wrong with your maven config (pom.xml). Try mvn clean install from the command line see if it gives any errors.
My IDE was not resolving JUnit & Mockito dependencies. Tried reimport in IntelliJ and mvn clean install multiple times which didn't help. Reimport worked for me, but with the following steps.
Please be aware that you will lose any run configurations that you have created.
Close IntelliJ
Go to Project Folder and remove .idea folder (rm -rf ./idea)
Import Maven project again (You will need to add back any run configurations that were deleted)
I solved this problem by adding mockito to module I used. Just go to File -> Project structure and in Modules add mockito to your selected module - the one in which you use mockito (usually Test).
You can also use command
mvn -U idea:idea
This command forces a check for missing dependencies and helps in resolving them.
Restartig intellIJ fixed that for me
For me, I deleted org.mockito package from m2 repository and then did mvn clean install.
this reimport the package.
Try using lower versions of junit and mockito.
The latest versions weren't working in my project but it worked once I used lower versions.
Few other things you can do:
After adding the dependency just make sure to update the maven
project. (right-click on project folder -> Maven -> Reload project)
You can also try clicking on the tiny m symbol on the top right to
load maven changes or select maven button to get clean+install
options and click play button.

How setup Thrift on windows using Intellij

I'm trying to create Thrift client project in Intellij on windows. I found many references how to create Thrift client using java in Intellij. But the problem is cannot add following references to the project. I am new to Thrif and Java.
import org.apache.thrift.TException;
import org.apache.thrift.transport.TSSLTransportFactory;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
what is the technique or method to setup on windows and import above libraries?
These instructions are not specific to your IDE, but neither is your problem. The library classes for Thrift are in libthrift-*.jar, and you'll need to add that to your project just as you would any other JAR.
If you are using maven, you can add the maven coordinates to your pom.xml:
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.9.1</version>
</dependency>
Alternatively you can just download the JAR and add it your project:
http://central.maven.org/maven2/org/apache/thrift/libthrift/0.9.1/libthrift-0.9.1.jar
If you are using a version that has not been published to the central maven repositories, you can download the source tarball and navigate to the lib/java directory and build it with Apache Ant by typing:
ant
The library JAR will be in the lib/java/build directory. Optionally you can add the freshly built JAR to your local Maven repository:
mvn install:install-file -DartifactId=libthrift -DgroupId=org.apache.thrift -Dversion=1.0.0 -Dpackaging=jar -DpomFile=build/libthrift-1.0.0.pom -Dfile=build/libthrift-1.0.0.jar

IntelliJ not loading transitive dependency in maven project

I've made a small library, lets call it lib. It dependends on another library, sublib which is available in Maven central:
lib/pom.xml:
<dependencies>
<dependency>
<groupId>3rdparty</groupId>
<artifactId>sublib</artifactId>
<version>x</version>
</dependency>
</dependencies>
Now I'm trying to use lib in my project proj. I've set it as a dependency:
proj/pom.xml:
<dependencies>
<dependency>
<groupId>mynamespace</groupId>
<artifactId>lib</artifactId>
<version>y</version>
</dependency>
</dependencies>
When I run mvn exec:java -D exec.mainClass=mynamespace.proj.Main the program runs fine.
However if I run it from IntelliJ, I get the following error:
java.lang.NoClassDefFoundError: 3rdparty/SomeSubLibClass
at mynamespace.SomeLibClass.method(SomeLibClass.java:100)
This seems to indicate that IntelliJ does not load the transitive sublib dependency. How can I fix this?
You can manually right click on the pom.xml file in the file tree and select maven > reimport.
Sometimes you'll see a popup saying "Maven projects need to be imported"; you should select Enable Auto-Import.
This option can be found in Preferences > Maven > Importing > [x] Import Maven projects automatically (and is unchecked by default):
What worked for me was changing from using maven (Intellij) version and using my latest version that was installed on my machine previously.
I had a similar problem. The below command resolved the problem. It downloaded all the dependency jars into my IDEA project.
mvn -U idea:idea

How to import org.apache Java dependencies w/ or w/o Maven

So the quick background is I am creating a java program, that uses many different imports
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.util.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
I know that Netbeans isn't finding these files because I do not have them on my computer. But is there a way to have Netbeans automatically connect with org.apache and retrieve these files? Or do I just have to go and download them. Someone recommended using Maven, but I am not sure if this is the right solution or how to go about that?
Thanks
Unless you use a Maven structure (see here getting started with Maven) you will have to download all jars manually.
If using only Hadoop (as in your example) this might not seem that much of a deal, but when working with big projects it is easier to declare your dependencies in a pom.xml file. It is much more easier than downloading X different jars, and you can easily move to a newer version of a library, rather than having to delete and and download another.
I saw that someone asked in a comment why people like Maven so much. Well, to be honest, I personally find it easy to use and very useful. Furthermore, a Maven project can be easily imported in IntelliJ, Eclipse or Netbeans, whereas creating for example an IntelliJ project can cause difficulties in importing it in Eclipse or NetBeans.
To get started using Maven with Netbeans, you can go to: New Project, Categories:Maven Projects:{Best Option}. Then in the project files, open pom.xml. Here is where dependencies for your project are added. If you are not sure what to insert try searching for your jar name + "maven" on the internet. The plugin for Netbeans is able to connect to the maven repository and autocomplete most fields.
Sample from: http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.6
<project...>
....
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
...
</project>
Download the .jar file here: http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-core/0.20.2
In Eclipse, right-click on your project, click Properties, search in the text box for Library, click on Build Paths, click Add External JAR, and select the file you downloaded from the link above.
You will have to download the jar-files yourself. Unless you start using Maven or a similar dependency management tool.
You must download them. The name org.apache.hadoop is a package name, and we only use the name of the site as a convention. See this tutorial on packages for more information. Essentially a package is a folder on your computer, often in the Java\jre\lib\ext\ directory.
Refer tutorial
http://www.tutorialspoint.com/hadoop/hadoop_mapreduce.htm
It mentions :-
Download Hadoop-core-1.2.1.jar, which is used to compile and execute the MapReduce program. Visit the following link http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-core/1.2.1 to download the jar.
Not a netbeans user , but I'm sure that even in netbeans, you have a maven plugin.
"Mavenize" your project, and when you will perform mvn clean install, you will get these jars to local maven repository.
With Eclipse I use the m2Eclipse plugin and it works really well for me.
This of course depends that these jars can be found in maven repositories over the net, such as maven central repository.
I have final figured out my preferred way to create a new Hadoop project and import the dependencies using Maven.
Using NetBeans I create a new Maven project.
Then under project files, I open the pom.xml.
I finally add inside of
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2</version>
</dependency>
After building with dependencies I am now ready to code.

Categories