I have a collection of 3 existing Eclipse projects that I want to make into Maven projects and I'm having a hard time understanding the relationship between the GroupID, ArtifactID and my Java Packaging, and the different directory structure that is created for Maven vs. Java projects. I'm pretty new to J2EE and completely new to Maven, so any advice is welcome! Let me describe my projects first.
The first project is IDMU_JAR. The base Java packaging is com.foo.util.merge and it contains Java classes like Template and Bookmark and the target jar file is com.foo.util.merge.jar
The second project is IDUM_WAR. The base class in this project is com.foo.util.merge.web and it references the IDMU_JAR project and contains only a few Servlets that expose the functionality in IDMU_JAR.
The third project is IDMU_EAR. Currently this is just a device for creating a deployment EAR that contains IDMU_JAR, WAR and it's dependencies.
My questions are:
Is my J2EE packaging and naming "typical" or have I already gone against best practices?
Am I better off creating the Maven Project and then converting it to a Faceted project and picking the facets, or should I be creating the Java Utility/WAR/EAR projects and then converting them to Maven projects?
This appears to have a big impact on the directory structure of the project, is this important?.
Does my Eclipse Project name have to match the Maven Artifact ID?
You can configure pretty much anything in maven from file structure to project special configuration. But If it's not absolutly necessery you should stick with maven defaults.
You can start with that project template:
javaee-essentials-pom
For the project namings:
GroupID: com.foo
ArtifactID: idmu-utils, idmu-war, idmu-ear
package: jar, war, ear
With Eclipse:
Start by using the template I provided. Importing as maven project from Eclipse should resolve all facets available automatically.
Related
Currently, I have a maven project that has a server running (using Jersey REST API). I also have a java project, I need to move all the contents of the java project into the maven project. The maven project is a subset of the java project. However, the maven project only displays the parts of the java project. However, I want a project that allows me to use maven and displays all of the other details from the java project.
I would've copied and pasted however I'm using git so I want to also preserve history.
I was thinking it would be easier to nest the maven project inside the java project but I don't know if that's possible.
Here's a picture of my package explorer to help explain everything.
Package explorer showing the maven project being a subset of the java project.
What I've tried is converting the java project into a maven project and then updating the pom.xml but then it doesn't link to the web.xml. Also, it tries to run the server with the name of the project name TeamProject. When infact it should run the url with the name client_server
I was considering just copying and pasting all the code into the maven project (from the Teamproject java project).
Actually nesting the java project inside the Maven project makes more sense, as it is the purpose of Maven to handle a project lifecycle. (also by default Maven will look for sources in the src/ folder which should ease the task of putting your Java project inside Maven's hands)
There are several possibilities I would see:
Copy your java project in the src/ of your client project and update maven accordingly (within the pom.xml)
Make your Java project a Maven project and aggregate the two projects in a parent pom (see Multi module maven project example)
Make your Java project a Maven project, and decide of a "Master" project between it and the client and compose one with the other (not sure that's a great solution)
Nesting your Maven project inside the Java project would not be so great because Maven could only handle the client and not your Java project, and then you'd miss on numerous functionalities offered by Maven (just look at how simple it is to get dependencies compared to downloading a jar and including it on the build path manually)
There is standard Java WebApp project. I need to use Maven to build/compile/deploy project to online server. There is an option to create new maven module module or to import project using pom.xml. Following probaby won't work because:
Project doesn't have maven project and pom.xml
Creating new maven module probably would mess up my existing project structure.
How to add Maven support to existing Java WebApplication in IntelliJ 12?
UPDATE:
I selected Add framework Support... > Maven. Generated pom.xml at project's root. Added maven-war-plugin. The following structure I have got. Is it any good / correct?
You should use maven standard project structure for maven applications. However, if you cannot change it, then you have to tell Maven where to look for specific files. Consider:
Using maven using non standard directory layout
Standard Maven structure
Also here are some interesting things to remember: http://wiki.jetbrains.net/intellij/Maven_FAQ
I have been working on maven for some time but never had this question before, Many times I created my maven project using a IDE wizard which helps me to create a maven project which has pom.xml pre-configured or the other way is to convert a general java project into maven project which generates a pom.xml. I have a question what exactly happens in the background when we convert this java project into a maven project. What will be configured and how does the java project detects it has a pom.xml.
Inside the .project file in the root of the Eclipse project, m2eclipse will add the org.eclipse.m2e.core.maven2Nature to it. This tells Eclipse that the m2e plugin will handle various stages of the project lifecycle, and m2e has a hybrid partially-internal and partially-external engine that applies the instructions in the pom.xml to the project. (For example, it finds the classpath placeholders that are marked as maven.pomderived and replaces them with the appropriate Maven dependencies.)
If i want to convert an EAR project a maven project , do i need to add the module in the deployment assembly as maven dependency or just use the convert in m2eclipse without any further configuration.
Me personally I wouldn't attempt any kind of conversion of an existing project. I would add the poms, make sure that mvn clean install works on the command prompt and then create a new mavenized Eclipse project from the poms.
The main reason is that you current project settings are effectively wrong when you switch to Maven - the Maven poms are the truth and what feeds the Eclipse project setup, so you really do not want to make your life difficult and work against m2eclipse - let it do the project creation for you. Fresh.
You can install m2eclipse and then do the following as well.
Go to the project menu (right click on Package Explorer) > Configure > Convert to Maven Project
Open the pom.xml and right-click and choose Run As -> Maven Clean. Similarly Choose Run As -> Maven Install.
Note : Please ensure that your eclipse project settings are correct and classpath libraries are not absolute and you don't have any project specific environment variables defined in your workspace. Please take a backup of your project before you do this.This is to ensure we don't mess up the current stable project configurations. Once m2eclipse generates the pom.xml for your project, you can update and make changes to it to
fully obtain a mavenized ear build. hope this helps
You can also try creating new maven project with archetype selection of "jboss-javaee6-ear" and follow the similar structure for your project. Most probably you will need parent Pom and child poms per each module (ejb, war, jar etc). There are other few similar approach but almost all of them requires you to have mulitple POMs
maven-ear-plugin and JBoss AS 7
You can also go through all the examples for maven ear plugin to find settings suitable for you
http://maven.apache.org/plugins/maven-ear-plugin/
I ended up ditching ear for war :) single POM and even ditched the JBOss for tomcat/jetty :)
If you want to convert your existing eclipse dependencies into Maven dependencies, you can try the JBoss Tools (JBT) Maven integration feature, which contains an experimental conversion wizard, plugged into m2e's conversion process : http://docs.jboss.org/tools/whatsnew/maven/maven-news-4.0.0.Beta1.html.
So, all you have to do is, as Keerthi explained, right-click on your project and Configure > Convert to Maven...
If your dependencies already are maven artifacts, it should work easily. If not, you'll need to convert them to Maven (if they're workspace projects) or make them available in your maven enterprise repository, before converting the EAR project.
JBT (requires Eclipse JavaEE) can be installed from http://download.jboss.org/jbosstools/updates/stable/kepler/ or from the Eclipse Marketplace (See https://marketplace.eclipse.org/search/site/jboss%2520tools)
I am trying to use JIBX maven plugin in my Spring Web Service project,
My project has diferent layers (API-DAO-SERVICE vsvs..)
these layers are individual projects and has maven dependency each other.
In my WEB project's POM, I add other project as dependencies, and my mapping
classes are all in API project.
Even in my web project's POM includes dependencies of API project I could
not use that class'es in JIBX
BUT IF I put that class'es in WEB project's src/main/java directory there is
NO PROBLEM,
How can I use mapping classes that are other maven dependent projects.
Any help is really appreciated;
Thanks.
Generated sources are supposed to be compiled and packaged in the artifact at the end. The classes should thus be visible from your webapp.
Did you setup the maven-jixb-plugin as shown in Generate Java Sources from Schemas? If not, then maybe update your setup first and try again.
And if you are still facing problems, please show the relevant parts of your POM(s).