I am trying to convert a Java project which uses Ant into a Maven project, but am having difficulties finding out which dependencies to include.
How do I find out dependency settings for a particular import?
Provided you currently have the jars on your build-path, at least in Eclipse, when you CTRL + click an imported class, and you have selected "link with editor" on the package explorer, the bytecode outline is opened and the file is selected within the jar it is located.
Then, having the m2eclipse plugin, you right-click your pom -> Maven -> Add dependency, and type the name of the jar there. In most cases that would do.
Another vote for jarvana. There are also (that I know of) mvnrepository.com and www.mvnsearch.org
You need to be careful and figure out the correct version of the jar you need. Also, the repos often have many duplicates; different names for what appears to be the same thing, so you need to figure out which one is the "real" one.
How do I find out dependency settings for a particular import?
The easiest way to do that (in a generic way) is to use something like Jarvana, a "Maven-Focused Java Class and Archive Search Engine".
UPDATE: You'll find more search engines in the Frequently Asked Technical Questions that I'm quoting below. I like Jarvana but I don't have any particular recommendation:
How to find dependencies on public Maven repositories?
You could use the following search engines:
http://repository.apache.org
http://www.artifact-repository.org
http://mvnrepository.com
http://www.mvnbrowser.com
http://www.jarvana.com
http://mavensearch.net
Related
I'm using an Eclipse project and don't want to use a Maven pom. I want to drop the jars needed for Mockito into a directory and reference them from Eclipse build properties. But Mockito.org doesn't supply a download link nor mention what jars are needed to get Mockito running.
How do I determine what jars I need to download?
Mockito.org is mysteriously evasive about what Jars are needed for specific releases. They really want people using the .pom, but sometimes we don't wanna use Maven. (Developers are capricious and stubborn after all.)
Here's how to derive what jars you'll need if you're willing to read a .pom:
Go to Maven.org and type "mockito" into the search box. Look for the latest version of a "mockito*" in the "artifact ID" column. Decide which .jar "looks right." In this case I used mockito-core. Click on the "jar" link and now you've got your first jar.
But you need to get the dependencies:
Click on the link to the .pom and look at the listed dependencies. You'll see listed artifact-ids such as byte-buddy, byte-buddy-agent, and objenesis.
Using the maven.org search box, enter in the artifact-id and download the jar for each of them. Put them all together in a directory and change your build properties so you can use Mockito in your Eclipse project.
Basically you are looking for
mockito-core.jar
and on top of that, you also want:
mockito-core-sources.jar
mockito-core-javadoc.jar
It often helps to have the source code, or at least the javadoc content at your fingertips within your IDE.
Most eclipse platform functionality is implemented in plugins.
I'm trying to figure out what plugin/s is/are responsible for certain functionality or actions. In my case specifically, figuring out which ones are responsible for import resolution in java files:
for the line import org.openqa.selenium.firefox.FirefoxDriver; eclipse will give me an error: the import org.openqa cannot be resolved (since I've never worked with openqa, and I haven't added it to my pom.xml file), while for the line import java.util.Iterator it just knows what we're talking about.
How can I find and dissect those behaviors, to better understand how the resolution works?
I know I can get a list of all installed plugins through: help -> about eclipse -> installation details -> plug-ins; but that isn't much help since that's just a huge list of suspects.
Conversely, I've tried running eclipse with -vm c:\jre\bin\java.exe -consoleLog to see the internal logs, but it looks like most plugins only log errors to the error log.
My guess is that using maven to enrich the project's build jars list, and some existing collection of multiple jars, eclipse will look in the project's build path to resolve the import. But that's just a guess...
Also, when the resolution fails, eclipse will give the cannot resolve import error, and allow me to figure it out through an import search window that doesn't actually find anything, which is what I'm trying to see it it's possible to improve upon.
The Maven plugin definitely plays an important role for looking up Java classes. If you right click on a project in Eclipse you should see a menu item that is called Build Path. It shows the dependencies of the project that are taken into account when Eclipse builds classes in the project. A dependency can be a jar, but it does not have to be. The dependencies include Maven dependencies.
This post is not an answer to the general question of finding a plugin that implements a functionality, but it's maybe enough for your specific case.
I am learning AOP with Spring framework and I want to set the javadoc for AOP in eclipse. So what I did I downloaded aspectj-1.8.10.jar from eclipse web site https://eclipse.org/aspectj/downloads.php#install then I installed that jar and got 4 new jar files: aspectjrt.jar, aspectjtools.jar, aspectjweaver.jar, org.aspectj.matcher.jar which I added to my class path in eclipse. Now what I want is to add source files for these jars so, for example, when I hover over #Aspect I want to be able to see what this annotation represents. Unfortunately I can not find the source files for these jars, on the eclipse website mentioned above there is a file aspectj-1.8.10-src.jar but I'm not sure what to do with it, I tried to attach this file directly in the build path for each of the jars mentioned above but it didn't do the trick. Also I thought that maybe I had to install aspectj-1.8.10-src.jar the way I installed aspectj-1.8.10.jar so I would get 4 source files, but I'm not sure how (if possible) to install it, when I double click aspectj-1.8.10-src.jar, installation does not get triggered.
So can you please help me out to add javadoc for AspectJ 1.8.10 in Eclipse?
Select the library in your Eclipse project explorer window, click right button, select properties, select javasource attachment or javadoc location and enter the path to the source or javadoc file.
But I would suggest to use maven to maintain the dependencies of your project. It makes getting javadoc much easier, because libraries, source code and javadoc are fetch from a central repository. You just add the library you need in your project configuration (pom.xml file) and the other files are fetched for you.
You do not need all those libraries. Please first learn which one serves which purpose. E.g. aspectjrt is the runtime. When using Spring AOP you actually do not really use AspectJ, only a subset of its syntax. Thus, the runtime is needed for identifying some of the annotation classes. However, aspectjweaver is only needed if you want to use full AspectJ in a load-time weaving (LTW) scenario, with or without Spring. The weaver lib is a superset of the runtime, so you only need one of them. Last, but not least, aspectjtools again is a superset of the weaver lib and contains the AspectJ compiler (among other tools). This is only needed for compile-time weaving as part of your toolchain.
I do not think that source code and Javadoc will help you much in learning AspectJ. I suggest you read the Spring manual's AOP chapter describing both proxy-based Spring AOP and full AspectJ integration via LTW. If you want to learn AspectJ basics and maybe just use AspectJ without Spring (which is what I do), read the AspectJ documentation.
If you are still not convinced and want to add source and JavaDoc to your Eclipse project, why don't you follow jaysee's advice and use Maven? Then you get all the source/javadoc libs for free. But anyway, you can also load those JARs directly from Maven Central, e.g. the source and javadoc for AspectJ runtime 1.8.10. Good luck! But I assume you will be disappointed because the AspectJ JavaDoc is really bad for learning purposes and not suited to understanding how to actually use AspectJ.
I have two maven projects imported into Eclipse in the same workspace. Both have a class with the same name and package, but different implementations and in different locations in each project. Let's call this class com.namespace.Factory
Project A has Factory under its test folder, i.e: /src/test/java/com/namespace/Factory.java
Project B has Factory under its main source folder, i.e: /src/main/java/com/namespace/Factory.java
There is also a Project C which is dependent on both. Project C also uses Factory from Project B for some of its unit tests. Problem now is Eclipse can't compile Project C because it can't differentiate between the two Factory classes. If I build all projects in command line, they don't have issues.
You would think that Eclipse would ignore the Project A Factory class since it is in test.
I am using the m2e plugin. My current work around is to setup m2e to not resolve Project C's dependencies within the workspace. This forces it to download the jar that will not have test in it. However, this means I have a change in either A or B, I have to manually install A or B push the latest jar to the local repo, and update Project C's dependencies to pull down the latest jars.
Is there a way to exclude the Project A test folder from the build path in Project C so that I can continue resolving everything within the workspace? It feels like Eclipse is breaking something that is fundamental to maven projects.
I think you're just another user affected by the upstream bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=376616
To sum it up, the bug report discussion includes:
JDT implements just one buildpath per Eclipse project. This is very unlikely to change, since this was fundamental design choice and many APIs and implementation details rely on that.
Well, but that doesn't really answer your question I guess.
So I see multiple options here, depending on how much influence you might have on the projects:
either try to rename one of the classes => names would be unique
or if the classes contain basically the same functionality, play with dependencies between projects, or even create new one, that the other 2 would depend upon
that's pretty much what comes to my mind right now
Perhaps you can try this:
In project A's Properties dialog (get there by right clicking the project and then click Properties),
click Deployment Assembly on the left.
Eclipse will show all source folders.
Select the test folder (/test) and click Remove.
With the maven-eclipse-plugin, using mvn eclipse:eclipse, you can specifiy eclipse project natures and builders that will automatically be added to the eclipse project.
Earlier versions of m2eclipse used the configuration block of the maven-eclipse-plugin and also let you activate natures and builders using the same mechanisms. This seems to no longer be the case because a) I can't find any reference to maven-eclipse-plugin in the m2eclipse sources and b) it just doesn't work :-)
So this is my question: is there any way to configure the eclipse project generated by m2eclipse from the pom.xml? Specifically: project builders and natures, but I'd be interested in other options as well.
The following thread summarizes almost everything. First, it explains that m2eclipse doesn't and won't support anything from the Maven Eclipse Plugin anymore because:
Sonatype doesn't maintain it.
It causes them too much troubles.
Second, it states that the m2eclipse way to handle additional project natures and builders is to write project configurators:
(...) we encourage writing configurators to add the natures and builders you want based on what it available in the POM.
See this link for a guide and this project for some existing configurators for checkstyle, findbugs, pmd.
I have now implemented this as a maven plugin I call maven-eclipseconf-plugin.
Unfortunately it's proprietary work for a client, so I can't share it. But let me describe what I do:
Tied to the lifecycle verify, I check for the existence of an eclipse .project file. If it's there, I check it for the presence of the builders and natures I want to automatically add (and you can deactivate this behavior by using a maven property or a stop file with a configurable name). You can also define configuration files that will be written (like .pmd, which is related to this other question of mine). The contents of the Configuration files can be specified inline, it can come from an external file, or from a URL. I also tried to introduce variable substitution in the config files where a special placeholder would be replaced with a multi-moduke-project's root folder, but I had to give up on that approach.
Anyway, the plugin gives me pretty much all the functionality of the maven-eclipse-plugin I ever used (of course there is a lot more though) and I'm happy with that. Perhaps I will build something similar once more in open source when this contract is finished.
Project configurators are the proposed approach. But the latest version of m2e-extensions is from early 2010 and developed against m2eclipse 0.10.x. There is a successor project called m2e-code-quality which is more recent and active and developed against m2eclipse 0.12.x.
But neither m2e-extensions nor m2e-code-quality do support FindBugs at the moment. And there are some other limitations with header files, exclusions and modified JARs.
I have successfully used a universal approach with AntRun, Ant and XMLTask to automatically add project natures, builders and configuration files for Eclipse plugins from pom.xml.