Source jar files in eclipse - 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.

Related

Can i use the google app engine eclipse plugin with a maven gae project?

I migrated a GAE project to a Maven project with the official way (https://developers.google.com/appengine/docs/java/tools/maven) but I don't want to use Maven to deploy/use devserver.
When I'm using the GAE Eclipse plugin I get an error:
Could not locate /path/to/project/target/WEB-INF/appengine-web.xml
Is it possible to use the GAE eclipse plugin or must I use Maven for deploying/local server?
I found the current process to do this a bit tricky, but it is possible. And it works pretty well after fiddling with it... I've been happy to have Maven manage the dependencies and I've found myself using it to test/deploy too. The key to getting it to work can be found in the GWT docs: In particular, you need to use a "dynamic web project" in Eclipse, rather than the normal (to me) GAE project.
Create the Eclipse Dynamic Web Project as in the link above, including changing the source folders to the proper maven-like location, and changing the web module location to the maven location.
Copy your source files in the right places.
Add the pom.xml file to the directory. At this point, you should be able to go to the command-line and run mvn appengine:devserver
Back in Eclipse, go to the project properties and turn on Google -> App Engine: Use GAE, and use HRD.
To be able to use m2eclipse to manage Maven dependencies and take Maven actions in Eclipse, you need to convert the project to a Maven project, as per this StackOverflow question
You might need to shutdown Eclipse, rebuild via Maven, restart/refresh Eclipse. At this point, you should be able to build/debug/deploy via Eclipse or via Maven!

How can I execute Maven goals from Eclipse without M2Eclipse?

I am using the eclipse plugin for maven to generate eclipse projects from maven pom.xml files.
mvn -Dwtpversion=1.5 eclipse:eclipse
This works fine and, after some experimenting with several of the 400 different archetypes available, I settled on using the webapp-javaee6 archetype, which was the only one which generated a set of dependencies that were both all available and which created a project that was useable by the WTP plugin.
The problem now is that I would like to be able to invoke mvn goals from eclipse. The accepted way to do this I understand is to use the m2eclipse plugin, which I have installed.
However, after playing around a bit and getting nowhere I discovered this comment in my .project file:
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
Further searching (see this lengthy diatribe from October) suggests I'm not (just) being stupid in not being able to get this to work.
The how-to linked in the top answer to this question seems hopelessly out of date.
So, the real question - what is currently the correct way to use maven to generate a WTP-friendly project that can be converted to eclipse and then use eclipse to call the project's goals?
Have you tried File -> Import -> Check out existing Maven Projects from SCM? My understanding is that m2eclipse will then create the eclipse project for you. If the packaging defined in the pom is war, the project should be deployable with WTP. (The latter used to require an the maven-wtp-integration plugin as well, don't know whether that's still the case).
Not sure about WTP or maven archetypes, but have you come across SpringSource Tool Suite (Spring packaged eclipse) and created a Spring Roo project? You can use this to create a data driven maven built web-app in a few mins. You can even remove the spring roo bits if you don't want them, it will give you a good starting point for a web-app with very little pain.

Managing external jar dependencies

I'v written a selenium framework which needs to be extended to the team. I've checked in the code in SVN. How can I make sure that external jars are added to build path and folder that folder by other team members? Basically I want to manage these dependencies better. Somebody said, Maven can take care of these so I tried to install m2eclipse plugin for eclipse 3.2 without any success. Can Maven solve this problem and is there any better way of managing it?
Do the easy way: commit the jars into SVN. It will save everybody a lot of time.
If you are amenable to using Eclipse, Maven, and m2eclipse, I would suggest using SpringSource Tool Suite. It is an Eclipse based IDE with Maven and m2eclipse pre-bundled. This bundling makes getting those three tools to work together very easy.

Eclipse Automatically Download / Update JAR files

I just created a Web App project from a repository through Eclipse's SVN support. What I would be doing is have an ANT build going and then finally deploy through Tomcat.
I am using Eclipse IDE for Java EE developers on an Ubuntu system.
There are a number of jar files needed
to support my project - like Struts,
Hibernate, etc. etc.
Do I need to
manually download each of them
and put them in the lib folder?
OR
Does Eclipse have a solution to
automatically UPDATE these from the internet? Any plugins to automatically take care of this?
You should consider using Maven for your project. It's VERY well supported in Eclipse, and handles all dependencies (as well as other things, such as releases).
The problem is there's a bit of a learning curve, but if you intend your project to get to a considerable size, I'd say it's very important.
Maven has support for ant builds and most libraries are in the central Maven repository. You just say your project has a dependency on the external project and it will automatically download the dependencies.
http://maven.apache.org/

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.