- This topic has 183 replies, 92 voices, and was last updated 16 years, 5 months ago by Riyad Kalla.
-
AuthorPosts
-
Aaron DigullaMember+1
(especially because of edross’ comment about provided JARs)!
Riyad KallaMemberJust so you guys don’t think we are ignoring this, I’m tracking all your specific feature requests and functionality requirements (like edross’s list). These specifics are very useful for us when sitting down and working on new highly-requested features to make sure we aren’t missing (right out of the gate) low hanging fruit that you guys need.
jklcom99MemberCan you some one show me an example on how to create a j2ee multimodules project using Maven2 and MyEclipse?
Thank you
Donald ScottParticipantPlease add maven plugins…
davidb27MemberMy feature request with this is for Maven to work as a Web Project, I have everything working well with Maven/Eclipse with the exception of the deployment.
It is a pain to run “mvn package” or “mvn war:exploded” and copy the files to Tomcat. It is slow because it does copies everything each time, and Tomcat needs to restarted.
If you set the WebRoot folder to be PRJ/src/main/webapps MyEclipse changes the class paths to compile to PRJ/src/main/webapps/classes, which is not correct for Maven. And Maven smart deployment will not pick up the other classes specified in the .classpath file when deploying to the container.
I’ve worked around this by creating another Project that is a web project with a dependancy on the class paths of the Maven project. However you have to sycnronise the webapp folder between to two projects. This also deploys the files in the Test folder as well.
Either way is a less than ideal solution.
Regards,
David
Aaron DigullaMemberdavidb27: Can you elaborate on this a bit? Maybe a small HOWTO setting up a web project with maven and ME including how to configure both?
Or maybe you can create a small HelloWorld app which you could share?
Ed rossMemberHere is how I do it.
1 – create the projects using maven archetypes
2 – create a parent pom
3 – modify the created projects to inherit the parent
4 – run mvn install to download all needed jars
5– run mvn eclipse:eclipse (this will create the project files for eclipse with the dependencies)
6 – import the projects into eclipse
7 – fix the web project
8 – tell my eclipse about itexample:
We want to create a project structure with the following
Web project
Services Project
Services Impl project
Dao project
Dao impl project
Data modelWe will call our organization dufus.org and the final application called sipit.
Step 1 – create the projects using maven archtypes
mvn archetype:create -DgroupId=org.dufus.sipit -DartifactId=sipit-web
mvn archetype:create -DgroupId=org.dufus.sipit -DartifactId=sipit-services
mvn archetype:create -DgroupId=org.dufus.sipit -DartifactId=sipit-services-impl
mvn archetype:create -DgroupId=org.dufus.sipit -DartifactId=sipit-dao
mvn archetype:create -DgroupId=org.dufus.sipit -DartifactId=sipit-dao-impl
mvn archetype:create -DgroupId=org.dufus.sipit -DartifactId=sipit-data-modelStep 2 create parent pom
This is just a very basic parent pom you could add repository, CiManagement, Reporting and a bunch of other stuff here.
<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”><modelVersion>4.0.0</modelVersion>
<groupId>org.dufus.sipit</groupId>
<artifactId>sipit</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Sipit application parent</name>
<url>http://www.dufus.ort</url><modules>
<module>sipit-datamodel</module>
<module>sipit-services</module>
<module>sipit-services-impl</module>
<module>sipit-dao</module>
<module>sipit-dao-impl</module>
<module>sipit-web</module></modules>
<!– these are used by all subprojects –>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jmock</groupId>
<artifactId>jmock</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<scope>test</scope>
</dependency><!– ensure we always have the right version of jakarta commons utils –>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies><build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*SystemTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins></build>
</project>
Step 3 – modify the subproject poms to use the parent.
In each of the subprojects that were created with the mvn create statement you will need to modify the sub-projects. Note the pom for the web project will be done a bit different, so we will do that one last
Service project – will need access to the DAO project and the DataModel
<project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>org.dufus.sipit</groupId>
<artifactId>sipit-services</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Services project</name>
<url>http://maven.apache.org</url><!– project relationships –>
<parent>
<groupId>org.dufus.sipit</groupId>
<artifactId>sipit</artifactId>
<relativePath>../</relativePath>
<version>1.1-SNAPSHOT</version>
</parent>
<dependencies><dependenty>
<groupId>org.dufus.sipit</groupId>
<artifactId>sipit-dao</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency><dependenty>
<groupId>org.dufus.sipit</groupId>
<artifactId>sipit-data-mojdel</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency><dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>do that to each of the projects and put in the dependencies where needed
For the web project need to modify a bit moreChange type the packaging to “web”
Add dependencies for all of the sub-projects (so when you use my-eclipse to deploy, everything is copied to the target directory)Step 4 run mvn install to download all the dependent jars
Step 5 – run mvn eclipse:eclipse –DdownloadSource-true (nice to have the source for the open source projects where available)
Step 6 – import the projects into eclipse
Create a new workspace (Not required but nice to put the project in a clean environment)
Menu – file/import, then go to the PARENT directory –
Select all of the subprojects and your done – well almost doneThe maven create did not set up the web project
Step 7 – the maven create did not quite create all the directories needed. You may need to add resource directories and for the web you will need to add a /src/main/webapp directory.
Step 8 – tell my eclipse about the web project.
Assuming you already have a Web server or App server defined in my eclipse, you want to add “web project” capabilities to the web project and a deployment
This should work if you have M2_REPO defined, if not, you will need to do this step also. You could do that with maven, but didn’t work well for me. I just defined it after.
Alternate
Use MyEclipse to create the web project, then copy the pom to the base project directory. This would work – but MyEclipse does not create project structures that same that maven wants them by default. Bummer
MyEclipse OPPS
Each time you add dependencies in a pom, you will need to do a mvn install, followed by mvn eclipse:clean eclipse:eclipse. This will wipe out any my eclipse meta data and you will need to set it back up again.
Aaron DigullaMember@edross: Thanks for the long HOWTO.
I have a couple of open questions, though:
– What do you put into the web project? Only JSPs/CSS? Or to ask from a different perspective, how many project do I need to have if I wanted the least amount of projects? Can I get away with having just a single project with all sources, JARs, etc.?
– Where would you put stuff like log4j.properties? Note that I need two of these: One for the tests and one for the web app.
– How do you deploy this? Especially, how do you tell ME not to deploy servlet.jar?
– How do you redeploy? Is it possible to change the code in the data model and just reload your JSPs in the web browser and see the change?
kdelongMemberI’d like to vote for Maven support as well. We have a webapp that is part of a multimodule build. We can’t use MyEclipse to deploy to any appserver. As a poster noted above, Maven compiles to the /target dir but MyEclipse points to /src/main/webapp/WEB-INF/classes, so it’s a bit of a mess. We had to write an Ant script that calls “mvn package” and then copies the WAR over…yuk.
Ed rossMemberI like more smaller projects, but you could do it all in one project (if not using ejb’s). I think it is easier to manage and control, and re-use, but that is just my opinion.
Project structure for a typical web project
src/main/java/ – all of the java servlet classes (or thoses that manage the view portion of the mvc)
src/test/java – all test classes (Junit, or easymock, ect) These should go here in the same package structure as the main
src/main/resoures – any log4j.properties, xml descriptors, spring-context.xml, ect (at deployment they end up in the classes directory)
src/test/resources – any resources needed for testing
src/main/webapp – base directotry for the web app. here is where you would stick the WEB-INF directory, possible html file, or style-sheets, etc. In the WEB-INF you would put the web.xml, jsp’s, other protected resourceshope this helps
Ed rossMemberIf you create the web-app using the mvn archetype:create … you will not run into the problem of myeclipse not deploying correctly.
mvn eclipse:eclipse will set the output folders to the correct place, and my eclipse seems to know how to deploy from there.
once the project is created, right mouse click on the project, go the myeclipse menu item and select add Web Project Capabilities.
There, set the web root context (scr/main/webapp) then deploy to tomcat, jboss, or what ever. My problem comes from clustering – we cluster in production so our jndi ejb’s can resolve, in test (Starting under myeclipse) we can not cluster because jboss barfs.
davidb27Member@digulla wrote:
Can you elaborate on this a bit? Maybe a small HOWTO setting up a web project with maven and ME including how to configure both?
Digulla,
Here is how I do it (sorry, not as comprehensive as edross)
1. Create a Maven project using the standard Maven tools (mvn eclipse:eclipse, etc). I also use the M2Eclipse plugin to make Maven work a bit better in Eclipse.
I then setup the classpaths. Using the Eclipse plugin means you don’t need to use the M2_REPO classpath variable at all, eclipse does it all for you.2. Right click the project, go into Properties > Build Path > Order and Export.
Ensure that your Maven Jar file dependancies are exported.3. Create a new Web Project.
Right – click the new project and go into Properties > Build Path > Projects.
Add your Maven Project.
Go into MyEclipse > Web > Deployment Tab. (still in properties)
Tick “Smart Deployment for Dependant projects”
Tick all the boxes under “Liberary deployment policies”4. Create your jsps, etc in the new Web project. Modify your Java code in the Maven project.
Setup the Project deployment for the Web-project.
The auto deployment will now work with the JSP’s from the Web project and the Java code from the Maven project.5. When your done/ready to commit you need to copy the files from the Web project into the Maven project /src/main/webapp directory.
davidb27Member@edross wrote:
If you create the web-app using the mvn archetype:create … you will not run into the problem of myeclipse not deploying correctly.
Ed,
If I create a maven project, then add web project capabilities Myeclipse will re-write the .classpath file to change everything to compile into /src/webapps/WEB-INF/classes instead of /target/classes and /target/test-classes.
If I manually change back the compile-paths MyEclipse will not deploy the classes from these folders. It still tries to deploy from /src/webapps/WEB-INF/classes.
I am only using a single-level project (with one parent POM for common dependancies, etc).
Do you have a way around this?
Thanks,
David
Ed rossMemberIf I create the project using maven, change the build type to a web project (package type is war) then do a mvn eclipse:eclipse the target directories will be project/src/main/webapp/WEB-INF/classes,
This is where the classes should be compiled to. When you add MyEclipse web project capabilities, the Web Root Directory should be project/src/main/webapp. This should cause a proper exploded deployment.
Were MyEclipse is compiling the classes is the correct place to build a war file.
I also include the following in my pom file (gift-client-web-admin is the name of the project) to make maven build to the same place as myeclipse (I guess I forgot this part in the previous explain ) -sorry
<packaging>war</packaging>
<build>
<finalName>gift-client-web-admin</finalName>
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
</build>
davidb27Member<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
Thanks Ed,
I see what you’re saying. I would prefer to keep the Maven standard layout though.
I think it would be better if the MyEclipse team fixed the web-deploy to pickup the changes anywhere in the project classpath, rather than forcing the classes to be compile into *WEBROOT*/WEB-INF/classes and then ignoring all other classes.
David
-
AuthorPosts