Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Struts 2 built by Maven HELP

 
Greenhorn
Posts: 10
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I am newbie to Struts 2 and Maven tool. I just finished the book "Head First - JSP and Servlet". The book said a little bit about Struts at the last chapter. So I tried to figure out how to work with Struts 2.
I googled online and found out many Struts tutorials ask users to build the project with Maven. I found two tutorials from Apache Struts site and Mkyong, both of them ask for Maven.
However, I get lost after starting with Maven. Here is what I did (learned it from Mkyong):

I built one empty web-app with:

mvn archetype:generate -DgroupId=com.pac -DartifactId=StrutsApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false



The results look good to me:


[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.pac
[INFO] Parameter: packageName, Value: com.pac
[INFO] Parameter: package, Value: com.pac
[INFO] Parameter: artifactId, Value: StrutsApp
[INFO] Parameter: basedir, Value: c:\maven_proj
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: c:\maven_proj\StrutsApp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.820s
[INFO] Finished at: Fri Jan 17 11:20:03 PST 2014
[INFO] Final Memory: 13M/244M
[INFO] ------------------------------------------------------------------------



Then I went to the project folder to modify the pom.xml to:


After the modification, I ran Maven to convert to project to Eclispe style:

mvn eclipse:eclipse -Dwtpversion=2.0



The results look good though. It shows downloading each Struts component from Maven repo:


Downloading: http://repo.maven.apache.org/maven2/asm/asm-commons/3.3/asm-commons-3.3.jar
Downloaded: http://repo.maven.apache.org/maven2/asm/asm-commons/3.3/asm-commons-3.3.jar (38 KB at 267.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/asm/asm-tree/3.3/asm-tree-3.3.jar
Downloaded: http://repo.maven.apache.org/maven2/asm/asm-tree/3.3/asm-tree-3.3.jar (21 KB at 262.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/freemarker/freemarker/2.3.19/freemarker-2.3.19.jar
Downloaded: http://repo.maven.apache.org/maven2/org/freemarker/freemarker/2.3.19/freemarker-2.3.19.jar (910 KB at 1715.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2.jar
Downloaded: http://repo.maven.apache.org/maven2/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2.jar (59 KB at 529.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/commons-io/commons-io/2.0.1/commons-io-2.0.1.jar
Downloaded: http://repo.maven.apache.org/maven2/commons-io/commons-io/2.0.1/commons-io-2.0.1.jar (156 KB at 865.4 KB/sec)
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "StrutsApp" to c:\maven_proj\StrutsApp.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.260s
[INFO] Finished at: Fri Jan 17 11:33:42 PST 2014
[INFO] Final Memory: 10M/244M
[INFO] ------------------------------------------------------------------------



Finally, I used "import the existing project" option to import it to Eclipse. However, after I imported the project, I checked the "Deployment Assembly" option in project properties, it showed me something like:


Cannot find entry: "c:/Users/xxxx/.m2/repository/org/apache/struts/struts2-core/2.3.8/struts2-core-2.3.8.jar"
....
....



In fact, I did see the Maven downloaded these .jar files. They are in the maven local repo directory instead of this "c:/Users/xxx/.m2/...." .
How can I fix this? Is it that I need to manually add these jar files to project from maven local repo directory? I thought Maven should import them automatically. Is it correct?

Thanks!
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not used Maven so I can't be of much help. I know Struts has some archetypes and instructions here.
I'll move this topic into our Maven forum to see if anyone there can chime in.
 
author & internet detective
Posts: 40797
828
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c:/Users/xxx/.m2/.... is the default location of the local Maven repository. You can change that in Eclipse to point to whereever your local repository is.

Eclipse workspace preferences > Maven > User Settings > Local Repository
 
Dian D Chen
Greenhorn
Posts: 10
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much! It works now~
BTW, when I read the tutorial from Apache Maven, it mentioned about setting M2 sys variable. Is that M2 same as this ".m2"?

Jeanne Boyarsky wrote:c:/Users/xxx/.m2/.... is the default location of the local Maven repository. You can change that in Eclipse to point to whereever your local repository is.

Eclipse workspace preferences > Maven > User Settings > Local Repository

 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dian D Chen wrote:Thank you so much! It works now~
BTW, when I read the tutorial from Apache Maven, it mentioned about setting M2 sys variable. Is that M2 same as this ".m2"?



M2 (M2_HOME) is the system variable that would point to the .m2 directory on disk. It similar to how the JAVA_HOME points to the Java home directory or CLASSPATH points to classes that should be included when java is invoked from the command prompt. Similarly M2_HOME gets used when Maven commands are run from the classpath
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic