How to build JGit in Eclipse (dependency errors) - eclipse

I'm trying to build the latest version of JGit. I checked out the latest version from the Git repository. According to the build instructions, I installed the dependencies via Orbit. I then ran mvn clean install which was able to compile everything and run all the tests. So this was great, there were no errors, and I can find the compiled .jar files.
I then opened Eclipse and imported the projects into a working set. For some reason, there are numerous errors in the build process.
Imports cannot be resolved:
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarConstants;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
And more cannot be resolved:
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
I tried installing Jetty via Eclipse (Install New Software). However, that did not resolved the issue.
Am I just not supposed to build JGit in Eclipse? All builds and testing should be done with Maven? I'm also confused as to why Jetty and Apache are being imported in some of these subprojects for JGit and they're not listed as dependencies of JGit on the wiki.
Thanks in advance.

The easiest way to install the dependencies is to use one of the target platforms, as described in Use a Target Platform. It includes all dependencies.
As for installing from the Orbit P2 repository, the listing there was incomplete. You also need to install "Apache Commons Compress", see updated instructions:
http://wiki.eclipse.org/EGit/Contributor_Guide#Option_2:_Install_from_Orbit_P2_Repository
Jetty can not be installed from Orbit, see here for instructions:
http://wiki.eclipse.org/EGit/Contributor_Guide#JGit_HTTP_Tests
Or again, use the target platform where Jetty is also included.

The Jetty and Compress libraries are used by part of the JGit infra, but the EGit support in Eclipse doesn't need everything that JGit has.
For example, JGit also provides a collection of command-line programs (jgit init, jgit add etc.) which are not used in Eclipse. So you need to build the 'pgm' module from MAven, but that in itself isn't used by EGit which is the UI in Eclipse. Similarly, the JGit HTTP server is useful but not required for EGit operation.
I believe the archivers are used to extract out tools via the pgm module for 'jgit archive', which extracts out the contents of a branch and generates a Zip or TGZ file on the fly.
If you don't want (or need) the pgm module (and i'd suggest possibly also avoiding the iplog as well) then you can uncomment those from the list of modules in the pom.xml file. Removing the http.server (and http.test) along with the pgm modules will probably allow you to compile without needing the Jetty and Apache compress modules.

Related

IntelliJ IDEA not loads all provided jars like Eclipse

When I am importing project in IDEA through Maven POM file, IDEA does not import "provided" jars like what Eclipse does by default. Classpath used by IDEA always falls shorts with jars and I am unable to run project.
What is the way to get IDEA yo import the same jar files as Eclipse does by default?
Currently what I need to do is to first import the project from maven (POM file) to Eclipse and then import the Eclipse project into IDEA to achieve the right result.
IMHO, the only really repeatable way to do this is to make the official, maintained build a stand-alone one (e.g. maven, gradle), and to have no dependency in your project (or your version control system) on any IDE whatsoever.
So, for instance, if you set up and maintain your build in maven, and use only external dependencies (no jars in your lib directory), then both eclipse and intellij (and netbeans, etc.) can load the pom.xml and build the code.
This also allows you to use a continuous integration server like Jenkins or Hudson.

Source jar files in eclipse

I am using eclipse and having difficulties in finding the related source jar files (including recursive dependencies) manually and linking each one of them to the 3rd party jars in the project class path. I need the source to understand the 3rd party functionality better.
What is the simple way to address this issue?
Your problem is twofold:
First, you have to get (read: download) all the source jar files you need.
Second, you have to tell Eclipse how to find the source jar for a given library.
If you create an Eclipse application (a product or plug-in based on Eclipse Platform or Eclipse RCP) which uses OSGi-Bundles coming from a p2 repository, and if the p2 repository contains the sources, you can usually install the "SDK" feature of the respective project to get the sources.
However, from your question I guess that you are developing a Java application (without OSGi or Eclipse runtime). In this case, I know of no builtin feature of Eclipse which could download and attach the source code for your library jars.
As Phantom Reference said, the best way is to use a tool which is able to download all the referenced jars including their source automatically. And, yes, Maven seems to be the tool of choice, because of its automated dependency management and resolution features.
BTW, if you don't want to use Maven (e.g., because you don't know it and you don't have time to get into it), you could still manually use a Maven repository to find the source (and binary) jars of most common 3rd party libraries there.
Have a look at http://search.maven.org.
I suggest you to move to maven build tool if you are not using it already.
You can configure the maven plug-in in eclipse to do this job for you.
Here are the commands to get the source code as well as the Javadocs by maven itself from command line.
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
Here is the screen shot from my eclipse Windows --> Preferences that shows how to configure Maven to download and attach the source as well as Javadocs, all automatically. Hope this helps.

How can I set the java.library.path used by eclipse from a POM?

I'm using maven to define my projects. One of my dependencies requires a native DLL at runtime, and consequently it's needed in tests and for debugging. The native DLL is available at a known location. I want a solution that I can check in once and will work for all developers without manual setup by each dev.
I know I can set the java.libary.path manually in "run configurations", which will allow it to find the native DLL, but this requires manual setup for each developer.
I know I can also set the java.library.path for a given project dependency, but again this is local to a particular developer.
Finally I know I can set the surefire plugin to specify the java.library.path, but this is only useful for tests triggered via maven - so it's great for our build server, but doesn't help devs using the JUnit runner in eclipse, or wanting to debug or run code directly from eclipse.
Is there a way out?
I've found that the eclipse m2e connector that goes with the maven-nativedependencies-plugin seems to fix this.
According to the mavennatives docs:
Since version 0.0.7 of the maven-nativedependencies-plugin if you have
m2eclipse installed and the nativedependencies plugin configured the
unpacking of natives will run automatically, you don't need the
eclipse plugin to unpack them. However in order to setup the
java.library.path environment variable in eclipse you will have to do
it either manually or automatically using the eclipse plugin.
This Eclipse plugin is an extension to m2eclipse, it detects if you
have the maven plugin configured, and if you do it executes the
unpacking of natives, and configures the Native Library Location.
If you import a maven project that has the mavennatives plugin
configured, and you have the m2eclipse integration plugin, on import
the natives will be extracted, also when performing a clean from
eclipse the natives will be extracted.
So, if you use both these tools, using native dependencies requires no
manual configuration, other than whats in the pom, just run your app
and it works.
If I have the connector installed, and add mavennatives to my POM, then reload the pom (right-click on project in package explorer > maven > update project), the "Native library location" of the project is populated automatically (to see this, right click on project > properties > java build path > libraries > native library location)
This seems to work for debugging, JUnit runner, etc.
It does require that every developer install the plugin, which is manual (as manual as installing eclipse); however, at least once installed once it will work for any/all native depdendencies configured for mavennatives via a POM.
The Properties Maven Plugin may help you passing the system properties by using properties:set-system-properties to set system properties.
The example should be look like the following: -
<properties>
<java.library.path>some/path</java.library.path>
</properties>
I hope this may help.

OSGi bundles dependency management in Eclipse

I have an OSGi bundle which is in Eclipse IDE represented as Eclipse Plug-in Project. The only way I found to satisfy the dependencies of this plug-in/bundle is to
1) import all dependencies (.jar files) through File > Import... > Plug-ins and Fragments wizard
2) and then declare the imported dependencies in MANIFEST.MF
Yes, this solution works, but on the other hand after I commit the changes to our repository all my team mates also have to manually import dependencies to Eclipse to fix the compilation errors.
QUESTION:
Is there a solution which does not require such irritating steps? I just want to pull the changes from repository and continue my work without need to fix the dependecies in MANIFEST.MF again and again...
P.S.: To retrieve dependencies we use Apache Ivy.
You need to set up a target platform in Eclipse. I find the easiest way is to put all the dependencies in a folder, and save the target platform as a .target file which I check into source control. Then the only steps my colleagues need to do is retrieve the dependencies and configure Eclipse to use the shared target definition. If we add new dependencies to the definition Eclipse will automatically pick up the changes with a restart or target platform refresh.
The Eclipse documentation should get you started: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.pde.doc.user/concepts/target.htm
If you develop server based applications then it is much better to let maven or Ivy manage the dependencies and use the maven bundle plugin to generate the Manifest. So you can avoid the Eclipse OSGi mode and the target platform. See http://www.liquid-reality.de/x/DIBZ for a tutorial how to develop OSGi bundles using maven and deploy on Apache Karaf. For Ivy you may have to use a slightly different build but the basics should be the same.

JavaRebel with a Multi-module Enterprise Project in Maven

Does anybody have experience working with JavaRebel, specifically for a large web application built using Maven? There is a JavaRebel plugin for Maven that seems under-documented, does anybody have comments on how it works, can you really update one class in a Multi-module Enterprise Project and have it "automagically" change on your Server?
Are there any issues with different IDEs and this setup? For example NetBeans will not let you compile one class at a time in a Maven project (from what I can tell).
Disclaimer: I work for ZeroTurnaround.
JRebel (formerly JavaRebel) installation involves the application configuration file "rebel.xml" and modifying the container startup command line.
The Maven plugin is used to generate the "rebel.xml" file, that is used by the JRebel agent running in the container to find the files in the workspace. This allows to use IDE building to compile .java files and skip the Maven build process, as the changes to files will be picked up from the workspace. However as it relies on the IDE to compile the classes, it does depend on the IDE ability to compile efficiently. I know for sure that Eclipse will compile classes one at a time and am fairly sure you can configure NetBeans and IntelliJ IDEA to do the same.
In addition to the Maven/rebel.xml configuration you also need to configure the container startup command line. You may also need to install and IDE plugin or do some additional configuration to have the best expirience with JRebel. Following through the steps of Installation manual ensures that.
Hope this helps.
Disclaimer: I've not actually used this plugin myself.
This tutorial implies that JavaRebel works well with Eclipse 3.4. If you are also using m2eclipse it should work ok with Maven projects as well (as long as you ensure that Maven and Eclipse are compiling to the same target folder so the Eclipse incremental compiler can be used to modify the class file).
According to this post, you should configure the javarebel-maven-plugin to generate the rebel.xml (used to mount external folders to the application classpath). There's also a general installation guide you may find useful.