Configure Eclipse project to run "mvn generate-sources" when building automatically - eclipse

I have a Maven project in Eclipse that's running some commands to generate a couple files (these files are placed on the Classpath of another Java project). When the "Build Automatically" option is checked, instead of running the typical builders, I would like it to run "mvn generate-sources", add that folder to the project Classpath, and refresh the directory so the new generated files are available to the other project.
I tried adding a custom builder that runs a dummy program and refreshes the directory containing the generated files, but when Eclipse detects that those generated files have been changed, it triggers another rebuild, which causes Eclipse to go into this infinite loop of rebuilding this project. How can this project be set up to automatically regenerate these files without sending Eclipse into this infinite loop? Does a custom plugin need to be created?

The other Builders in the project were causing the infinite loop. Right clicking the project -> Properties -> Builders -> Deselect all the other builders in the project except the custom one.
After doing this, the project properly rebuilds itself automatically without going into an infinite loop, and the other projects pick up the changes automatically.

Related

Configure eclipse to perform different tasks on save

I migrated my projects to use the Gradle builds for all actions (building, testing, etc). When I save in eclipse, it builds with the default eclipse actions. Is there a way to change eclipse's behavior so that when I hit the save button or Ctrl-S it will run gradle build?
In the Project Properties on the Builders page you can control which builders are run when the project changes. You can disable existing builder and add new one using either Ant or running a program.

How to remove launch configuration histories in eclipse?

Right click an arbitrary existing project in Package Explore, choose "export..." - "Java" - "Runnable JAR file", I find all the old projects in the "launch configuration" list. Those projects have already been removed from the disk, and are not visible in the Package Explore. How can I remove them from that list? I'm using eclipse indigo.
This question seems to be well answered here, however, to make changes I have simply deleted every undesirable launch configuration from the below path.
${WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches/Delete all the .class LAUNCH Files
After deleting the files, it is necessary to restart Eclipse for the changes to take effect.
Under Window...Preferences...Run/Debug...Launching...Launch Configurations, you can activate and deactivate some filters that restrict what is shown in Run...Run Configurations. I think it is what you are looking for.
Eclipse menu -> Run -> Run Configurations... pops up the list of all viable run configurations, grouped by type. You are looking for those under Java Application. Any of these are deletable. Delete them and they will no longer show up in Run/Launch configuration lists.
Go to Run->Run configuration. Delete the existing saved projects under the Java Application.
Run the class, having main method from eclipse. It will be automatically set.
create runnable Jar.
Go to Run->Run configuration. Delete the existing saved projects under the Java Application.
Then run the class, having main method from eclipse. It will be automatically set.
Now create runnable Jar.

How do I associate my custom ANT builder with the project instead of the Eclipse workspace?

I'd like to associate some ANT targets with my project's build in Eclipse.
No problem, I create a custom ANT builder, specify targets to run, all is well.
But then I realize that the builder information is saved in the workspace instead of the project! Why is that, and how do I fix it?
The goal is that anyone who imports the project in a new Eclipse workspace can build it without adding the builder manually. This means that I should have the builder configuration under source control, which means it should belong to the project, not the per-user workspace.
Maybe I'm just missing something?
There is a bit of confusion, it seems, because builders look like launchers, but they are stored in a different directory. Simply creating the .settings dir and copying the xml doesn't help...
When I create the .externalToolBuilders directory under .settings and copy the launcher/builder there, I get this:
Solution:
I restarted from scratch, deleted the project-specific data in the workspace directory, but left the .settings dir in the project dir. Re-created the builder/launcher, and Eclipse automatically created it in the correct place, and also added it to source control.
Indeed, your launcher (Run/Debug launchers or External Builders launchers) are saved by default in the workspace.
<workspace>\myProject\.externalToolsBuilder)
You can move that directory (.externalToolsBuilder) manually in the .settings directory of your project.
And uncheck the option "Delete configurations when associated resource is deleted" as mentioned in this SO answer.
With a full refresh of the project (or even a delete, followed by a reimport), your local version of .externalToolsBuilder should be taken into account.
For the Debug/Run launchers (not your case), you also can (since Eclipse3.4) use one of the Import wizards:
File > Import
type launch configuration, and you can import said configuration directly within your project.

Eclipse doesn't see my new junit test

I'm using eclipse to run the tests in a single junit(4) test class. The tests in the class all run just fine. Then I add an additional test and run the class through the test running in ecplise again. Only the old tests are run. The new test isn't seen by eclipse. There's no error or anything, it's just as if eclipse is looking at an old version of the test.
If I run the tests using maven, everything works fine. Additionally, after I run the tests in maven, ecplipse can see and run the new test correctly.
Any ideas what's going on? Any ideas how to get ecplipse's test runner to see my new test cases?
I had the same issue. I solved it by doing the following:
Going to Project -> Properties -> Java Build Path
For the source folder src/test/java, the output folder was set to
"Default output folder"
Setting this to the typical Maven target/test-classes directory in your Maven structure
After this, Maven and Eclipse were in sync (as opposed to Eclipse happily running an older version of the tests, from whenever the last Maven compile was).
Maybe you "just" need to create a new Run configuration. Eclipse "remembers" the latest used Run configuration and just repeats it if not told otherwise. To make sure you have a new Run Configuration you can rightclick the test case in the package explorer and choose Run As | Junit Test. Next time you hit play this will be the "remembered" Run configuration etc.
Possibly src/test is not in the Java Build Path.
Solution on Kepler:
Project -> Build Path -> Configure Build Path -> Source -> Add Folder
Then check the box corresponding to test under src
You might find this is likely caused by using Maven to build (Maven usually builds into the 'target' folder), but Eclipse is using a different build folder for its own build process. Simplest way is to go into the target folder under your Eclipse Project (or Bundle if using OSGi) and delete the conflicting subfolders/class-files from under that directory; for me this is my "target" folder. Then get Eclipse to rebuild, and everything should be fine.
Technically, and alternatively, you could just blow away the entire build/target folder if you wanted to, and let Eclipse rebuild everything.
In response to the answer provided by Ryan Dawe, I have found out that Default output folder can be set to only one folder, for all the source folders on build path. So if i changed the output folder to target/test-classes, my src/main/java was also outputting classes there.
You might have written this response for a different older version of eclipse, but as of Mars.2 release, we can only have one default output folder for all source folders.
The best solution i have found so far for this problem is to just include the target/test-classes as a class folder, by going to Project -> Properties -> Java Build Path -> Libraries -> Add Class folder.
It seems that your project wasn't recompiled. Either check Menu:Project/Build Automatically or do it manually as Boris Pavlocic commented.
This seems to be the same issue as junit not using the newest file
The problem seems to be that Eclipse puts the compiled tests in the wrong folder which can be solved by manually specifying where they should end up.
Add "test" in front of your test classes if not there already the #Test annotation isn't always picked up from Eclipse's Junit Test framework.
Here is how i fixed my problem...
right click project and go to Run As -> Run Configurations...
select JUnit -> [project-name] on the the popup that came up
(this configuration of [project-name] was created for me by eclipse
but if not there you can right click JUnit -> New and create it)
goto Classpath tab
highlight User Entries and click Advanced... button
on the Advanced Options popup that came up select Add Folders and click OK
on the Folder Selection popup that came up scroll to your project open up target and select test-classes and click OK
repeat steps 4-6 for the [project-name]/target/classes directory and any other directory needed in your classpath (like properties files used in your tests etc.)
Note: this assumes your project's default output folder for tests is target/test-classes, if it is not then adjust accordingly. Also, make sure you have the right JUnit version selected under the JUnit Run Configuration as well and your src/test/java directory is a source folder to your project, etc. as mentioned by others.
It means that you have created a Test class that you havenĀ“t build yet.
After a build, for example with "gradle build" the Test class will be found by Eclipse too.
In my case I had to make a cleanup before as well.

Why is eclipse trying to compile files not in my build path?

I have a rather large project which contains a number of third-party dependencies which are linked via svn:externals. These include tomcat and blazeDS, which are packaged by our installer via ant. The problem is that these projects contain dozens of sample JSP pages, and eclipse chokes on them when trying to build the project, producing hundreds of errors.
Our project setup is something like this:
src/
main/
test/
third-party/
blazeDS/
tomcat/
etc.
Now, in eclipse, my project's build path is set to only include subfolders in src/main and src/test. Yet, for some reason, it still tries to build everything beneath third-party. I have clicked on third-party and selected "remove from build path", but this had no effect. I even tried adding the third-party folder to the build path, and then excluding "", "/*", and "**/*.jsp", but again, to no effect.
What is going on here?
Edit: Thanks for the suggestions, though unfortunately, they don't seem to fix the issue. I don't have the CheckStyle plugin installed (I'm using Eclipse 3.4.1 with the only custom plugins being subclipse and flex builder), and I tried disabling all extra builders except for Java, but the errors are still being thrown.
I usually have this kind of issue with CheckStyle plugin, where you need to specify in its properties (right-click on project -> Properties -> CheckStyle):
"Exclude from check Files non located in a source directory"
Otherwise it does analyze (and reports warning/errors on) files which are not candidate to be compiled in the first place.
Couple of other suggestions:
try restarting your eclipse with the -clean option (eclipse software version of 'did you reboot it ?' ;) ). Beware it can reset your workspace perspectives, so you may want to try that with a copy of your workspace instead.
try deleting your project (your workspace reference of your project, not its actual content), and reimporting it (beware of your custom launchers, they may get removed in the process).
check if you do not have any linked directory within src or test, which would point to thirdparty(/**): that would explain the unwanted compilation.
It could be that your eclipse project is configured to have extra Builders. You can check that in the project's properties (right-click on project -> Properties -> Builders).
In my case it was because there was a reference to the file (which I had excluded from the build path) in another file which was in the build path. I wanted to exclude SegModel.hpp from the build path, but in another file, I had specified template short K::KEstimate<SegModel>(SegModel& m, short stepCode);