Maven IDEA plugin (or eclipse plugin) - java

From what I have understood, it is not the best way to open a project built with Maven in Intellij by using the idea plug-in, that is by calling:
mvn idea:idea
but by open directly the pom file (Intellij has default plug-in for Maven); the same thing, for eclipse.
Could you provide some arguments on why this is a better approach?

This applies equally to IntelliJ and Maven:
changing pom.xml file is not reflected in your IDE, you must rebuild the project (possibly losing some configuration (?)) every time. Moreover, if any team member modifies pom.xml, you have to remember about rebulding your project (which will require closing and reopening it).
additional step is required when opening new project
IDEs have some other Maven features, e.g. both of aforementioned environemnts can show dependency graphs
Use mvn plugin as a last resort only when your IDE goes crazy and cannot figure out maven configuration correctly.

For eclipse, the maven-eclipse plugin is not really maintained

Related

Eclipse and Gradle classpath out of sync: cannot be resolved to a type

We are having a frustrating problem with our Eclipse workspace. Here is a high-level example of what is happening:
ProjectA
-- src/main/java/...
-- build.gradle
ProjectB
-- src/main/java/...
-- build.gradle
After running gradle eclipse and importing the projects into Eclipse, we occasionally will get 'MyType cannot be resolved to a type' even though the following are true:
Our projects have the Gradle library container on their classpath
The projects have the correct workspace projects within their Gradle container
Things like CTRL + Click work from types that are showing up with red underline (i.e. compile error) meaning Eclipse knows exactly how to get to those types, but the compiler can't find them
Command-line Gradle builds work as expected
This is happening throughout the team and we cannot figure out why Eclipse keeps going out of sync and cannot compile from time to time. What usually fixes the problem is a combination of:
Project > Clean in Eclipse
Gradle cleanEclipse or gradle eclipse
Reimporting the projects
etc
Other notes:
Using Gradle version 2.2.1
Happens in both Eclipse Luna and Eclipse Mars
Using JDK 8
Has anyone else had these types of compile issues in Eclipse with Gradle projects?
One source of such problems can be letting Gradle generate the Eclipse project metadata/setup files (what you get by running gradle eclipse). I know that the Maven and Gradle teams really want their tool (Maven or Gradle) to generate that stuff, but they notoriously do a less-than-ideal job of it. For example, the last time I used Gradle it configured the .classpath to use a hard-coded JRE library path instead of the preferred Execution Environment. That kind of poor job of generating files makes for developer headaches.
Instead, the Eclipse recommendation is to manually configure your projects (for the most part), only letting Gradle manage its Classpath Container, then checking in the Eclipse .project, .classpath, and .settings files/folders in to your SCM (svn, git, etc.). That way, the process of checking out a project into a workspace is automatic and does not require running gradle eclipse or mvn eclipse:eclipse all the time.
That's the way that Eclipse projects were originally designed and intended to be managed, and it works very well. I've worked with setups like that on very large projects (100+ separate projects in Eclipse and dozens of developers). It also cuts down on the number of steps to go from zero to running app.
This is one of those philosophical differences between Maven/Gradle and Eclipse; when it comes down to it, IMO, the IDE should manage it's stuff and the build/dependency tool should just stay out of the way.
Try manually getting things just right in your project configuration and then checking in those files - see if it doesn't relieve the headaches your team faces in this area.

Eclipse makes wrong choice of JAR as project dependency when class presents in more than one library

I work on a big Java application and I'm having problem compiling it under Eclipse Kepler:
the application is based on Maven 3.1.0 and successfully compiles there
I generate Eclipse configuration (project files) using mvn eclipse:eclipse
The problem is that certain classes present in more than one JAR (e.g. imagine a class Http and two versions of this class where newer has more methods) and Eclipse makes a wrong choice of the depending class (older one) for particular project which makes it not compilable.
I tried to move Jars up/down in the project dependencies and it helps in certain situations, however, it means that I'm changing configuration changed by Maven.
Is it possible to configure Eclipse so that is "smarter"? Is it caused by Maven (POM files, a bug in Maven's eclipse plugin, ...) although maven compiles the project without any problems? Any other suggestion?
You should not use mvn eclipse:eclipse. The official way today is to use the m2e plugin (which is much smarter) with File->Import->Existing Maven projects.
When you open a pom.xml file you can see the dependency hierarchy and why a given jar was chosen.
(Note that most but not all standard distributions of the latest Eclipse contains m2e. If your do not you can download it from the marketplace, but it may be easier to download a distribution that has it).

How do i avoid the redundant "maven-update" in eclipse if i have 2 maven projects while one needs the other as a library

I have two java-projects configured with maven. One is a lib to the other. I always have to do maven install, maven update that my main projects gets the updated lib, when i change something.
Is there a way to avoid the annoying maven install / maven update procedure (in other words to automate this process)?
You can use the M2Eclipse plugin for Eclipse, which provides dependency management within Eclipse. If you have both projects open, it will automatically refer to the other project, without the need for mvn install. Any changes you make in one project will immediately be visible in the other - as long as your POM refers to the current version of the other project (usually SNAPSHOT).
If you develop them at the same time, It's probable that they shoudl be two modules of one project. If you set up them that way eclipse can manage their dependecy withou installing the lib into the repository.

How to correctly version control (svn:ignore) a Java project (Maven, Spring)?

i was on a 2-day training introducing as to Java EE. We used there Java EE, Spring Framework, Maven, Springsource Tool Suite (Eclipse), Tomcat.
I took the Eclipse workspace we created there and run it on my work PC. I had, if i remember correctly, only to configure Tomcat properly, and it worked on my PC.
Now i want to save the created Eclipse workspace containing 5 "sub"-projects in subversion so that my work colleagues can checkout this to them and run it on their computers.
How to do this correctly? I found somewhere a svn:ignore rule:
.classpath
.project
.settings
target
Using tortoiseSVN i added to the folder with the workspace this ignore rule, but the found out that the underlying folders target were'nt deleted so i deleted them manually and "added to ignore list". But after that the project in spring source tool suite does not see the mevan dependencies (i think so) because the imports are broken. STS underlines org. in the imports and says it can not resolve this.
How do i correctly version control such a project?
In my project we are using Maven and Eclipse (Helios, currently) and the Maven plugins for Eclipse:
Maven Integration for Eclipse
Maven Integration for WTP
We only have the pom.xml file and the src/ directory tree in our version control system. We make sure not to add the eclipse files there. Then when a new developer starts in the project they do Import -> Maven -> Existing Maven Projects. The Maven plugins for Eclipse then set up perfect build paths, settings and so on.
This way it is also very easy to re-import your projects into Eclipse as needed.
So, my tip is to leave the Eclipse files out of SVN and make sure you can setup the project correctly automatically simply by importing a Maven project.
If I understand your problem the right way, you need to configure Eclipse in order to be able to launch tomcat from it. The key, here, is not maven anymore, but Eclipse, I think. As you've made modifications in your workspace that can't be put in your maven configuration file (the pom.xml), you become "Eclipse dependant".
The key here is that, as you're Eclipse dependant, you need the Eclipse configuration files to work. Consequently, I'm afraid you need to add back .classpath, .project, .settings to your versioning tool... It's not generic, because you force people who work on your project to use Eclipse. But if everybody in your team do so, it shouldn't be a problem.
As I don't use Eclipse anymore, I don't know if versioning theses files can lead to problems. However, I hope this answer will help you to configure your project back...
EDIT : to be more accurate... and maybe give a better answer.
When using a version control system, the main goal is often (always ?) to give all the keys to use the sources, and develop from them. Consequently, you need to put in your VCS your sources, and all the configurations needed to use them efficiently.
In your specific case, the key is that you've become Eclipse dependant through its Springsource Tool Suite plugin. Consequently, it becomes essential to add the configuration files for this tool, because they can't work without them, and if they can't work, you can't work.
I can tell you my way of subversioning maven eclipse projects. First, when you create the project structure you have to commit the .setting, .classpath, .project files into the subversion repository. If you can't do this the other colleagues will can not use the project structure after checkout. After you commit the project structure, the best way is not to commit these files except only when you change something important eclipse or build path settings, because the others will have conflicts due to the system dependent informations. Never commit the maven target directory. Sorry for my english. Hope it helps.

Create Eclipse java project with a java programm

I would like to generate Eclipse Java Project with my Java program. When I click a button: it will generate an eclipse project with the parameters I specified (source path, library, ...)
My questions are:
is there a way to do that ? and how ? (api).
it is possible to generate Net-beans project too ?
Best regards,
Florent
Maven enables this and many more things around creating, bulding, testing and developing Java projects.
Create a Java project from command line. Then, using Maven create NetBeans, Eclipse or IntelliJ IDEA specific project files. Or even easier, just import already created Maven project directly from these IDEs.
Create Java Project in Eclipse first. Then look into directory created. You should find there two files: .project and .classpath. These are the files you should create in your app to get what you want.
Also for eclipse available M2Eclipse plugin to provide some Maven feature from Eclipse IDE.
http://m2eclipse.sonatype.org/
While Maven is the way to go in the long term, the best way to start a project in Eclipse is:
Hit Ctrl+N and choose Java project
Fill in the project name fields
Copy your files from wherever they are to the newly created project (ensuring to preserve package hierarchy)
Refresh project from File menu
Create a Run / Debug profile to run your app.
It should be fairly simple to get up and running this way.
The reason people recommend Maven is because Eclipse is an IDE. It's great for development but its no good for resolving external dependencies or for command line / automated builds. Maven is an IDE neutral way of building and becomes essential the more dependencies a project pulls in.
Unfortunately Eclipse integration with Maven is pretty clumsy and can be summarized with these very broad steps:
Install Eclipse Helios
Install m2eclipse from the Help | Eclipse Marketplace
Mess around with eclipse.ini to make Eclipse start from a JDK.
Configure m2eclipse to use any existing Maven local repository
Hit Ctrl+N and create a new Maven project and skip archetype selection
Copy all the source files from the old project into the new ensuring to use Maven's conventions for file locations. (e.g. source goes in src/main/java)
Create a Run / Debug maven target to clean / install the app
I say broad steps because there are a lot of gotchas. For example if the source is Java 5+ you might have to tweak the pom to set the compiler level. Best to get Eclipse working and then worry about Maven.
Netbeans has vastly better out of the box support for Maven although IMO Eclipse is still the better IDE for other reasons.

Categories