Project name different from artifact-Id - eclipse

When I import Maven projects from my workspace and these projects are children of a parent project, they're imported with project name exactly like the artifact-id. But when I import a parent project, the project name is just like the directory name.
Example of directory structure:
project-parent (artifactId = project-application-parent)
--web (artifactId = project-webapp)
--core (artifactId = project-core)
When I import all projects my workspace looks like this:
project-parent
project-webapp
project-core
What I want is to parent project be named like his artifact-id (project-application-parent). Is there a way to achieve this?

When you import maven project, click on 'Advanced' panel on the bottom of the import dialog and there you can choose an alternative name template.
The default is [artifactId], but you can choose, for example, [name] which is the content of the description tag from pom.

It is possible setting the projectNameTemplate property in the configuration of the maven-eclipse-plugin, as in Documentation.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>x.y</version>
<configuration>
<projectNameTemplate>custom-project-name</projectNameTemplate>
</configuration>
</plugin>

One way to rename the project is directly editing the .project file. This is a XML file located in the project folder with basic eclipse information about the project.
Just change the node (it will only affect the project name in Eclipse)

The problem occurs if the project is located in the workspace. If you move the project out of the workspace, the problem no longer occurs.

Related

Mapping maven structures to Eclipse structures, then analyzing with JDT

I'm trying to generate Java unit tests using Eclipse's JDT. Part of that is determining the classpath that pertains to a particular Java class.
I imported a Maven project named jaffa-framework into Eclipse. Jaffa-framework has several Maven modules, including jaffa-api. Each of the submodules has its own pom.xml. I can build jaffa-framework and its submodules with no problem using Maven from within Eclipse (although it will not build using Project -> Build Project).
<project ...
<artifactId>jaffa-framework</artifactId>
...
<profiles>
<profile>
<id>normal</id>
<modules>
<module>jaffa-api</module>
...
</modules>
</profile>
</profiles>
...
</project>
When I import jaffa-framework into Eclipse as a Maven project, I see the following in the UI:
A Java project: jaffa-framework
Two Folders/IPackageFragmentRoots for jaffa-api:
jaffa-api/src/main/java and jaffa-api/src/test/java
One "plain" folder: jaffa-api
This structure looks weird to me. I expected to see something more like:
jaffa-framework
jaffa-api
jaffa-api/src/main/java
jaffa-api/src/test/java
Perhaps I did something wrong while importing? If you have ideas, please let me know.
If I select a Java file within jaffa-api/src/main/java, I can use JDT to navigate to the jaffa-framework project and get its classpath using javaProject.getResolvedClasspath(true); however, what I really need is the classpath for jaffa-api.
The jaffa-api folder contains a pom file, a .project file, and a .classpath file. I don't see an easy way to navigate to it using JDT, and because it is a folder, I don't see how I could obtain the classpath programmatically using JDT.
I'm also wondering why jaffa-api looks like a plain folder, instead of something more project-like. Eclipse must know that it is some kind of subproject, because the folder contains .classpath and .project files.
Please tell me how I can access the classpath information of jaffa-api using JDT, and/or how I can correct my project set up.
There was something screwy about my original project creation. I'm not sure what.
I solved my problem by deleting my jaffa-framework project by right-clicking on it and choosing "Delete" from the menu. I re-imported the project using File -> Open Projects from File System. I'm guessing the key thing to notice here is that the "Search for nested projects" box is checked. After the project was reloaded, both jaffa-framework and jaffa-api appeared as projects.

How to only include some files on a Eclipse project?

I would like to create an Eclipse project from an existing project made with IAR Workbench.
I have a list of files I want to build, but I don't know how I can tell Eclipse to only include some files only.
I've discovered that I can "exclude" a file by clicking on the file then choosing Resource Configuration/Exclude. I've also found that I can place some filters on Resource Filters, but I have found where I can just include some paths such as
${workspace_loc:/${ProjName}/Foo/Bar/foo.c
How is it possible to do this?
I am going to answer my own question: you can't.
What you can do is to list the files on your Git repository and the files that should be excluded from your Eclipse project. Then you make the difference between both list to get the list of file that are on Eclipse.
Then from the .cproject file you can edit the key
<storageModule>
<!-- ... -->
<configuration>
<!-- ... -->
<sourceEntries>
<entry excluding="{{file}}|{{file}}..."
</sourceEntries>
</configuration>
</storageModule>

pom.xml greyed out when importing maven project into eclipse

In eclipse Mars, I could always clone a git repository and then import it as a maven project. But this time, the pom.xml is greyed out. On the next screen only the pom of another project is showing and I can't proceed.
Are you sure you have not already imported the project into the workspace? Maybe you just don't see it. One reason can be that you are using working sets and the project is not in the group you'd expect it to be in?
If the project is already imported into your workspace, and you are trying to import another copy of the same project that resides in a different folder, you can try adding some string for Name Template under Advanced and the importing.

Creating second customized POM in eclipse

Within a maven project under eclipse, I want to have a second(or customized) pom.xml in which I can use plugings like the assembly-plugin.
The problem with this plugin is that it requieres an outputh path which is only interesting for me.
Since I'm using git to push to a remote repository, I don't want to pollute the version controlled pom.xml with my private paths and other stuff.
I read about inheritance and multi-mode possibilities, but I only need two poms:
1) One for the public with general settings
2) One only for me with cusotimzed build options
I tried to create a second pom file and wanted to build the project with a new run configuration, but I don't know how to pass the -f parameter(which should call a different pom) in that dialog.
Thanks for hints or best practices.
Example of what I want to put in the custom pom:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>some\private\path</outputDirectory>
<finalName>SomeName</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</plugin>
Select the second POM in the Package Explorer, right click -> Run As -> Maven Build...
That should run Maven with the custom POM.
If you don't get the Maven options in the "Run As" menu, go to the "Content Types" preferences page -> Text -> XML -> Maven POM XML.
Add the name of your custom POM so Eclipse understands that this is also a POM (I'm not 100% sure it will look inside a file to determine the type).
If that also fails, you can use a trick: Write a small tool that takes the unmodified POM, adds the XML which you need and then runs Maven. On Linux, you can use shell scripts for that. On Windows, a small Java program might be easier. Or have a look at PowerShell.

How properly import maven projects to eclipse?

I have complex Maven project, which has a parent folder with parent pom.xml and some subfolders for subprojects, each with its own pom.xml.
When I checkout the parent folder from a SVN repository 'As maven projects', it correctly appears in the workspace each as separate project.
But now I made a checkout of the parent folder from other branch of project. I want to add this parent folder in the same manner to the current workspace. So I just select Import > Maven project, get the same dialogs as due checkout from svn, Eclipse finds all pom files with proper hierarchy and ask me give other name to parent project, cause the same name alredy exists (trunc version of project), I give it other name. But after import I get only parent folder as maven project in eclipse, all other subprojects are simple located under parent project as its subfolders.
So, how can I import such project properlty? I just want all subprojects created as maven projects too.
Eclipse doesn't allow one project to be imported more than once, in your case from trunk and a branch. This article shows how you can bypass this limitation with a custom maven profile. Basically, the steps are:
Add the following profile to your parent pom.xml
<profiles>
<!-- Specific profile used to append a string to project name -->
<profile>
<id>append-to-project-name</id>
<activation>
<property>
<name>append.to.project.name</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<projectNameTemplate>
[artifactId]-${append.to.project.name}
</projectNameTemplate>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Before importing the project to Eclipse, let maven generate the project settings:
mvn eclipse:eclipse -Dappend.to.project.name=[your-branch-name]
Import the project to Eclipse as an existing project (not a maven project).
This should solve the naming issue.
As for import of child projects: I also have a parent maven project with child subprojects and use the m2e plugin for Ecplise. When I select Import > Existing Maven Project, I can check both the parent and children. After import, I have both the parent project and each child imported independently. Screens:
So I hope this combined with the naming solution above should solve your problem.
For importing complex (or indeed any) Maven projects from an SCM (be it SVN, Git or any other SCM) I use the following approach:
File->Import->Check out Maven Projects from SCM
This works best if no IDE specific files have been committed to the SCM. It will import all nested projects or you can choose which projects to import. It relies entirely on the Maven settings for determining the nature of the project being created so that, assuming the POM files are correct, you wind up with everything configured just right.
You may need to install add-ons so that m2eclipse can access the SCM of your choice.
I guess there might be some workspace issue. You might have checked out the project in workspace itself(not sure so pardon for that).
What you can do is, try checking out your project in some other drive and then import the parent project. You will again see all POMs aligned in hierarchical way and then i suppose, you won't be asked for entering name for parent project and this will do the trick.
Delete the projects that you had checked out as Maven projects, then check out the parent project simply (not as Maven project), then Import the child modules as Existing Maven projects. Make sure they are listed as child modules in the parent POM.