I'm running into a bit of a strange issue with eclipse 4.18 that I'm hoping someone can help me with. My project is a jetty webapp that does some communication with an external server over FTP. I'm using mockftpserver (https://mockftpserver.org/) to assist with unit testing the code that needs to communicate with the FTP server.
I have the library dependency defined in the pom as
<dependency>
<groupId>org.mockftpserver</groupId>
<artifactId>MockFtpServer</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
I then have an import defined in my test class like
package my.project.test;
import org.mockftpserver.fake.FakeFtpServer;
public class TestGuiceModule extends GuiceModule {
}
Nothing too exotic going on, and maven seems to be able to run the compile. Eclipse however does not seem to be able to see the library. I have a bunch of errors along the lines of
The import org.mockftpserver cannot be resolved.
I double checked the build path and I can see the library listed under 'Maven Dependencies' and the package structure of the jar matches my import statement. Even stranger, I have other 'test' scoped dependencies in the pom.xml and eclipse is detecting those just fine. I'm at a bit of a loss as to why it is having an issue with this one particular library. Any suggestions on what I could do to track this down?
I was eventually able to solve this by deleting my settings folder and .project file and reimporting the project (see: Eclipse throws NullPointerException during Maven update).
The project was originally created in an older version of eclipse, but I thought I would be ok since I was checking out a fresh copy from the git repo. Apparently something must have gotten checked in that the newer version of eclipse didn't like.
I am using my local jar project in another project through a maven dependency.
<dependency>
<groupId>some.groupid</groupId>
<artifactId>some.artifactid</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
The jar is getting liked to the project but when I try to access any class from it, say com.companyname.app.Abc; it is imported as com.companyname.app.Abc and not just Abc with import statement separate.
I even tried putting import statement separately, but that did not work.
The IDE I am using is IntelliJ.
It was pom related issue where few of the plugins were causing the issue.
I tried creating project from scratch and got the difference.
I know there are tons of questions and answers about this problem, but none of them helped.
I have a jar, which I would like to import to my local java project.
I have created the project on IntelliJ IDEA with Spring Initializer.
I have used this command to install the jar into ~/.m2 repo
mvn install:install-file -Dfile=C:/Users/xxxx/Desktop/xxxx/lib/mylib-1.2.11.jar /
-DgroupId=com.test.custom -DartifactId=mylib -Dversion=1.2.11 -Dpackaging=jar
Then I have added these lines into my pom.xml file
<dependency>
<groupId>com.test.custom</groupId>
<artifactId>mylib</artifactId>
<version>1.2.11</version>
</dependency>
I have no errors, everything seems in order.
However, when I want to import a class from that jar.
import com.ca.bla.bla.MyClass
I receive an error called "Cannot resolve symbol "MyClass".
How can I solve it?
I have tried to create a lib folder and copy the jar in it and add it as a module
I have tried to create a localrepo for maven
They all gave me the same result...
Thanks in advance
I downloaded old project, which based on Eclipse, Ant or something else, I don't know this build system (I use Maven\Gradle). Project sources was converted to Maven manually, but project had more jar libraries. They were imported in project with help of IDEA (Project Structure -> Modules -> Dependencies), but libraries defined only in .iml file.
When I tried to build project in .jar with help of Maven — Maven show errors, that it cannot find classes from libraries (but in sources all good). I found in Internet example, like in this code sample:
<dependency>
<groupId>example</groupId>
<artifactId>example</artifactId>
<version>examle</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/example.jar</systemPath>
</dependency>
But this don't help. Libraries are old too, and they created by old build tools, which don't write artifact id, group id and etc., so I don't know this information.
How I can write dependencies on local .jar libraries in pom.xml if I don't know information (group, artifact ids) about they?
UPD_0:
When I try to set only system path to library, I take this:
All you need is set correct path in the
<systemPath>${project.basedir}/libs/example.jar</systemPath>
group, artifact ids and version are user defined information. So you can define it as you wish.
Try to install this jar in ur local repository from command line / terminal like this. Then add the dependency with the package and version given by you in the command without scope as system
mvn install:install-file -Dfile=<path>/example.jar
-DgroupId=com.something
-DartifactId=example
-Dversion=<give some version>
-Dpackaging=jar
-DgeneratePom=true
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.