Eclipse with m2e not building tests - eclipse

I have an Eclipse project that uses Maven. The regular source files (ie, in src/main) build fine in both Eclipse and Maven. However, the test files (ie, in src/test) will only build in Maven. I cannot find any way to get them to build in Eclipse.
That is, the tests in Eclipse are run as the last version which Maven compiled. Before I used Maven, tests would be compiled automatically when they were run in Eclipse. "Build automatically" in the project menu is still enabled.
This only affects the tests (which are JUnit 4 tests). As mentioned, the regular source files are being built automatically correctly.
Here's the POM file, with irrelevant data pruned: https://gist.github.com/anonymous/10001049

Add the src/test directory to your build path. Windows / Preferences / Java / Build Path, or something like that.
Updating the project might also work, since m2e can get out of sync with your pom file quite often.

Related

How to import playframework sources into eclipse?

After cloning playframework from github and importing java sources into eclipse there are a lot of build errors shown.
Running the goals from ant file in eclipse works fine as well as building from cli directly.
How can i resolve these errors in eclipse?
I took the following steps to import play into eclipse:
new -> other -> Java>New Java Project from Existing Ant Buildfile
select play/framework/build.xml
checking the 'Link to the build file in the file system' checkbox
Finish
The errors result from differences between eclipse internal build path
and classpath available for ant at runtime.
First Eclipse only imports rt.jar from system path. This may lead to
missing dependecies in javax.net packages (e.g.
javax.net.ssl.SSLException), which is located in jsse.jar. To fix, right
click on project->Properties->Java Build Path->Libraries->Add Library->
JRE System Library.
Second, play has dependencies to classes from ant runtime. To fix, right
click on project->Properties->Java Build Path->Libraries->Add
Library->User Library
There you have to add a new User Library (perhaps call it ANT) and add
all ant-jars from your ant installation (/usr/share/ant/lib/ worked for
me). Then add this user library to play projects build path.
From the Oliver's answer, I had also to add the jce.jar lib in my classpath.
It comes from the $JDK/jre/lib directory.

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.

eclipse ant integration and code formatting

I have configured Eclipse to use ant for doing the builds by setting the builders in project properties to point to the ant build script.
The build goes thru fine. However in my eclipse project I have not imported the required jars as a part of the project settings. All of this is done in ant's build.xml.
So in the java files, I get red squiglly lines for all the import packages which eclipse is not able to resolve.
How do I make these squiglly lines go away? One way is to import the required jars in eclipse, but then I am maintaining the project at two places, ant build.xml and eclipse
go to Project Properties/Build Path and enter the jars you rely on there.
You could use Ivy to manage your dependencies. If you configure it properly, you will only be defining the jars in one place but both Eclipse and Ant will be able to see them. The eclipse plug-in is IvyDE.

NetBeans -- Is it possible to bypass the IDE-generated Ant build for an existing project?

I have a Java project with sub-projects that is currently built using NetBeans's IDE-generated Ant scripts. I am converting the entire project to a Maven build.
My Maven build works fine from the command line and loads perfectly in Eclipse. However, the only way I can get the project to load as a Maven project in NetBeans is to delete the Ant scripts, i.e. build.xml and the directory nbproject for each sub-project. It seems that as long as I have the old IDE-generated build files, NetBeans recognizes the project as a NetBeans Java project only, not as a Maven Java project, even though there is also a pom.xml file present.
Short of deleting the IDE-generated build files, is there any way to tell NetBeans to load the project as a Maven project?
I have been told that we want to keep the Ant build for a while during the transition to Maven.
Using NetBeans 6.9.1, Maven 2.2.
Any help would be appreciated.
Thanks
Well, the nb ant project metadata has precedence over occurence of pom.xml file (that's how maven projects are recognized and loaded). The whole precedence order hardwired in the IDE, you could only influence it be uninstalling the j2se ant project type for example.
So, yes. You need to get rid of the ant project metadata before you can open the project as maven project. Depending on how and when you delete the metadata, you might need to restart the IDE as well to get the new stuff loaded.
Have you seen http://wiki.netbeans.org/MavenBestPractices? It indicates that you must install the NetBeans maven plugin first. Perhaps that's why your Maven projects aren't recognized.
I must note that I'm not a NetBeans user anymore!
Here is what I ended up doing:
I wrote an Ant script (ironic, huh?) that, for every subproject of my project, renames the file nbproject/project.xml if it exists to nbproject/nb_project_disabled.xml. If nbproject/nb_project_disabled.xml exists instead, the script renames it back to nbproject/project.xml. In this way, the script toggles the opening of the project as a NetBeans Ant build or as a Maven build.
It would be nice if NetBeans, you know, had a setting to open both kinds of projects. Currently (6.9.1), there is just the "Open Project" command. In Eclipse, there is the command "Import Existing Maven Projects" vs. "Import Existing Project Into Workspace" (i.e. native Eclipse format).

Eclipse - JUnit / m2eclipse classpath problem

I'm building a GWT application with Maven for dependency resolution and I've got a strange problem with Eclipse when trying to run JUnit tests. I have a standard maven-like structure of sources and tests:
/src/main/java
/src/test/java
If I set the the Java Build Bath > Default output folder of all source folders to:
/MyProject/target/classes
then there are no problems. However, the GWT plugin needs the sources to reside in:
/MyProject/src/main/webapp/WEB-INF/classes
in order to be able to deploy from this directory in development mode, otherwise it complains. However, if I set the output directory of all source folders to this directory, the tests are failing with ClassNotFoundException.
This can be worked-around if I manually add the directory /MyProject/src/main/webapp/WEB-INF/classes to the JUnit launcher's classpath, so, obviously, the compiled .class files are missing and hence the exception I get. But why doesn't eclipse add the directory to the classpath automatically if I define it to be the default output directory?
I suspect the m2eclipse plugin to be overriding the Default output folder setting, can it be? Because if I set the output folder for /src/main/java to /target/classes and src/test/java to /target/test-classes, everything works. But if any output directory is set outside of these two, it doesn't work.
I would appreciate any ideas, thank you!
m2eclipse has a storied history of ignoring the project classpath settings when running unit tests. It used to be (0.12 version of m2eclipse and earlier, I think), that if you just gave up fighting and set your project default classpaths to but target/classes (for source code), and target/test-classes (for unit test code), everything would be happy. With 0.13 m2eclipse, this no longer works, as the maven builder appears to put things in target/your-artificat-version-SNAPSHOT/web-inf/classes. Basically, the folder for the artifact that maven builds. This really sucks, since that path includes a version number.
m2eclipse has about exhausted my patience ;-).
A tip: To find out what is going on with your unit test class paths, you can always DEBUG as unit test, then right click on the thread in the debug perspective and pull up "properties". This will show you the complete classpath used for the unit tests, and you can see what the sneaky annoying plugins are doing to your classpath.