source is missing when debugging maven build configuration - eclipse

I have a maven build run configuration which I use to start tomcat server. Barely this is tomcat:run command which is executed by m2eclipse plugin.
That was all fine until I needed to jump into spring source code. I can not set source code lookup for debugger!!! All jars have their source code location setup, so I can open spring classes by Ctrl+click. But debugger seems does not understand this settings, I tried to add project to source code lookup, but that worked only for code that is in that project and not in its dependencies.

Try Igor's source lookup feature, it will help you get jar sources automatically during external process execution (maven plugin invocation, in your case).

Related

Force the use of an alternate POM file in eclipse

In my maven project I usually use the POM file named pom.xml. I have a second POM file though (call it pom_alt.xml), which I occasionally use to perform a very different build of the same project. To do so I specify the -f option in the command line
mvn clean package -fpom_alt.xml
as suggested by man mvn:
-f,--file
Force the use of an alternate POM file.
Now, when I am coding in eclipse I usually need maven to use pom.xml, but sometimes I should code or debug while the other file pom_alt.xml is used instead. Is there a way to tell the eclipse maven integration to use that file? Currently I am temporarily copy-pasting from pom_alt.xml to pom.xml since I seldom happen to need that, but you can see that's not optimal.
I am with Eclipse IDE for Java EE Developers, Mars Release 4.5.0.
UPDATE
I could build from the command line or use Run As Maven build as in
Carlos Andres' solution, but ideally I would like to define a persistent setting, like a property or preference. This because I find nice if the POM file can be fixed while I am doing things like running as Java Application and test cases, or executing on a server. Processes that require a project clean or server restart are often triggering a maven build with the default POM.
Check that M2E - Maven Integration for Eclipse is installed on Eclipse. Once that is installed go to the project and press right click
Next, put the command that you want to execute
This option allow you to save the commands, and the next time all your commands will be saved.
To execute the command recorded go to

Download sourcecode/javadoc automatically for Maven projects on Spring Tool Suite

I'm using Spring Tool Suite in my organization for writing Java code. We have a bunch of Maven projects. Whenever I do an F3(Open declaration) on a library's method, the class file opens up and then STS automatically starts downloading the source code and in a few seconds I see the source code in the editor. How does this happen? I've been trying to replicate this on my home machine to no avail. I looked at other similar posts, the usual suggestions are -
Check Download Source / Download Javadoc in Maven settings
Update Maven settings file to instruct Maven to download source/javadoc
None of these are done in my project. So, is there any other way to do it? We are using artifactory as remote repository, if that helps.

Walkthrough the spring source code

I wanted to walkthrough the spring code. For that I cloned the code and built it using ./import-into-eclipse.sh command. There are some instructions given in README.md file for checking out source in eclipse.
After following above instructions I was able to see the spring code in my eclipse workspace. To refer the spring source from my project I added all of spring projects (like spring-beans, spring-aop etc) in my project's Java build path. I was able to use spring code in my project.
Now the issue is that whenever I run the test cases in my project, I get initialization error. I removed spring projects from my java build path and junit test started working.
I tried to dig into the issue. For that I tried to run some of the test cases of spring projects itself like BeanUtilsTests.
but I got:
Class not found org.springframework.beans.BeanUtilsTests
java.lang.ClassNotFoundException: org.springframework.beans.BeanUtilsTests
I verified that classpath is set:
Don't know what is the issue. Can someone please tell me that what I did wrong.
Is there any better way to view/edit spring code?
Usually the below error,
Class not found org.springframework.beans.BeanUtilsTests
java.lang.ClassNotFoundException: org.springframework.beans.BeanUtilsTests
occurs when the corresponding jar is missing in the classpath. Since you have already added the spring-beans jar manually, I suspect you are using an incompatible version of the spring-beans jar with your spring-boot.
You can check the Maven repo Spring Beans to check the compatible version. But I would suggest using a dependency management tool like Gradle or Maven to include the required dependency jars. Spring-Boot Gradle file

Grails Project - Common Java Project Dependency in Eclipse

All,
We have standard java projects that contain our common data model, common util classes, etc...
What I can’t seem to figure out is how, to make my Grails project (in Eclipse) have a dependency on the other standard (non Grails) java project in the workspace. When I add the project in the “Java Build Path” the project doesn’t show any compiler errors, but it when I run “Grails Tools -> Refresh Dependencies” or attempt to run the project (run-app) it fails.
This seems like it would be a pretty common thing, but I have searched all over the web and have been unable to find a solution. We are not using maven in our environment. Since we build Eclipse RCP applications on the client side, we use OSGI manifests to manage our project / bundle dependencies.
You can use linked source directories to include the Java or Groovy dependencies in the grails project and you need to set the output directory to Project/target/classes (these configurations go into the grails project preferences in Java Build Path options -> Source Tab).
The change in the output directory allows Eclipse to detect changes in the dependencies and auto load it when running the app using grails run-app.
You can use autocomplete and debug the sources of the dependencies with this configuration.
I prepared a step and step process that includes screenshots for Java and Groovy here
The documentation includes information on customizing the build.
You can add this to your BuildConfig.groovy:
grails.compiler.dependencies = {
fileset (dir:"/path/to/jars")
}
That should get you started.
If the dependencies are not stored in an Ivy/Maven repository then AFAIK your only option is to copy the dependencies to the lib directory of the Grails project.

Extract eclipse project .classpath dependencies into ant script

I have a list of Eclipse projects that I would like to compile based on the existing project configuration.
As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and perform a "javac" compilation in the right order. This would save time in describing the same dependencies again in the ant script or a Makefile.
The dependencies I am interested in are JAR Dependencies, JRE dependencies, and inter-project dependencies. These are -- as far as I can tell -- part of the .classpath XML file.
Any ideas on how Eclipse project dependencies could used in an ant script?
Right click on your Project -> Export
"General/Ant Buildfiles".
Choose the projects and there you go.
Otherwise...
I have some experience with ant4eclipse and it is a hassle to get it stable.
Go check Buckminster or Maven Tycho for a good solution.
I'm currently using Ivy along with Ant, Eclipse and Maven.
I just love the way Ivy works.
Currently, we have a workspace with many projects using Liferay (with Tomcat) for the front-end and Glassfish for the back-end.
We were looking for a way to manage our dependencies a lot better than how we were doing it.
So I took Ivy, replaced all of the classpaths and deployment dependencies in eclipse and was able to build my application using 1 ivy file per project using either Eclipse or Ant.
Ivy integrates like a charm in ant and builds are done either from the workspace or by command line.
I strongly suggest you look at this avenue. Additionnaly, by adding Artifactory, we have a local repository in which the ivy files look for dependencies. This helps us maintain and rule which jars are to be used by developpers. Once everything is setup, we will build our application nightly using Jenkins and these builds will be using our Artifactory repository to resolve dependencies since our build servers do not have access to the internet.
Hope this helped
If you are running the Ant script only from eclipse using the "External Tools Configurations", you can add the variable ${project_classpath} to the Classpath.
Depending on if you are in a plugin project and dependencies you might need to add the
${eclipse_home}.
In case you get an error launching Variable references empty selection: ${project_classpath}, make sure the ant xml file or at least the project is selected. This is important.
I believe the ant4eclipse project provides support for executing Ant builds based on Eclipse metadata files.
However, in my opinion that is doing things back to front. You shouldn't have your build (Ant) depending on your IDE (Eclipse) environment. But it is useful if you can derive your Eclipse environment from your Ant build.
This is an approach used successfully in a team I worked in. We had a helper Ant target which applied XLST to project build.xml files to transform these into Eclipse .classpath files. Thus the Ant build.xml files were the single configuration point for our projects.