How can I create web fragment project in Intellij Idea - maven

I'm looking for creating a small web framework on top of the standard servlet-3.x specifications. Main motive is to reduce the boiler plate codes and abstractions. After I read the servlet specifications it looks without using JAX-RS or SparkJava I can create small web framework for API developments.
I'm planning to use the web-fragments method to create my framework level filters, and other beans and package it as jar. So application developer create the war project with web.xml with the metadata-complete option set to false.
I can see the web-fragment project template in eclipse but I want to develop this project using maven. With Intellij I can't see any such options for web fragment projects alone. I want to create simple maven project which ship the jar with web-fragment.xml in it, so other war projects can make use of it.
So is there any plugins or other options available to develop web fragment projects in Intellij ?

Any jar file added to the WEB-INF/lib directory of a web application is technically a "web fragment", whether it has a META-INF/web-fragment.xml file or not.
Therefore, you just need to create a maven project with "jar" packaging and import it into Intellij Idea.

Create a maven project for the fragment. Set the packaging to jar. There is no need to create a war project.
Configure an empty Artifact in the Project Structure dialog:
Using the toolbar buttons, add the WEB-INF/lib folders. Then create an Archive and add the compile output:
Add a Tomcat run configuration, and in the Deployment tab, add the Artifact you just created:
I created an example project that includes all that: https://github.com/ThomasR/web-fragment-idea. Please note that it requires TomEE+.

Related

Difference between a JSF and a Maven project

For my new JAVA application, I want to start creating a new JSF2.2 project with IntelliJ. This project will be a web application and will be using maven.
In IntelliJ Idea, when i click on "create a new project", and then in the left panel select "Maven", it gives me the option of "create from archetype". If I select this check box, it gives me a list of archetypes, with many including jsf in their names.
I am confused what is the difference in creating a maven project without these archetypes and giving it my own groupId, artifactid and so on as compared to creating a project with any of the given jsf archetype?
Like I stated above, the project that i am starting will be a JSF based web application.
EDIT 1
I made the project with maven-archtype-webapp and it created a file index.jsp in the webapp folder. Is this a problem as i normally work with .xhtml files
Maven archetypes are templates. They create a proper project structure for you, depending on whether you want to create a standalone, JSF, ear etc. project.
All these projects are built with Maven, and create a GAV (groupId:artifactId:version) for the created artifacts.

Explain structure of Eclipse-Maven Web project in Spring using Kepler

I am using Kepler to build a Eclipse-Maven project in eclispe. While making the project I am skipping archetype selection on first wizard. then I am selecting packaging as "war".
Eclipse provides me a basic structure after above steps. However, as this is my first Spring/Maven application, I am unable to completely understand the structure.
My Main issue is where to keep my web.xml. No WEB-INF folder is provided, while a META-INF folder is provided.
Also where to keep the basic Dispatcher-Servlet for project and others like root-context, servlet-context etc..
Do I need to create these folders by myself. If yes, Where please? As I am creating a RESTful service, I won't have any views but I guess web.xml is still a must. Currently I am unable to upload an image(nothing happens when I try uploading), will try again soon.
While making the project I am skipping archetype selection on first
wizard. then I am selecting packaging as "war".
You need to select the maven archetype as: maven-archetype-webapp to get the WEB-INF folder & web.xml
Check this out

How come my spring mvc web app works without pom.xml?

I have removed pom.xml from my eclipse project folder.
And I choose run on server option and everything works fine.
I am new to Spring MVC and have been given this project as an interview round.
Spring version 4.0.6, Tomcat 7, Eclipse Juno
Any help here is appreciated.
pom.xml is the build configuration file for the Maven building tool, Using Maven is optional as you can use any building tool of choice, for example Ant, Maven, Gradle ... etc
The idea behind this build configuration file is that you can define all your dependencies of your project (Spring, Struts, Hibernate, ... etc), source code repository, test cases classes, war file generation info, any other configuration for your project. and If you want to give me your project, you could only give me that pom.xml, and I would simply run maven on this file, and it will download your source code and dependencies, run test cases, build war file and deploy it on application server.
For more information, check the POM reference here
pom.xml is a maven configuration file. You don't need it to run a Spring MVC application.
Having said this, sin maven is what you usually use to build a project, you are not going to be able to build it again if you removed the pom.xml file.
Possible reasons:
You did not reference any Spring MVC class in your Web Appliction
Your Tomcat already has the Spring MVC in its libraries
Spring MVC libraries are copied in your Lib folder of your Web project, so they are carried along within the war (or exploded by the Tomcat plug-in for Eclipse).
As Pablo pointed out, you do not need Maven to add dependencies to your projects.

Can maven create a project from a war file?

I want to create a adobe flex blazeds project. How can I create the project using the blazeds.war as the project template ?
war -> maven
you can't do that, there's no way maven can guess how the war was produced only by analyzing the result
generating a project stub for blazeds
that you can do. You can used a defined archetype like this one: http://code.google.com/p/maven-blazeds-spring-archetype/
it will force you to stick to the technology (spring) chosen by the archetype developer, however.

Java web application modularize with spring

I'm trying to build a project structure like this:
Project
|--Web_module.war
|--Data_module.jar(Spring)
|--Util_module.jar
|--other public api...
which means, different modules should be packed into different jars, so i have to have more spring configurations(application-context.xml) for different modules (e.g. for data module and for web module).
My question, how could I organize all the configuration files to include them correctly in the web module.
Thanks in advance.
Plan to have a single eclipse project for each jar file that you anticipate.
Choose the jars files / eclipse projects as per your project functionality to be modular and self contained, as far as possible.
Use junit tests in each eclipse project to thoroughly test individual projects/modules, using spring unit test support
Each eclipse project will contain its own spring config context file eg Util_module project might contain a util-context.xml
Finally have an eclipse dynamic web project as a wrapper web application which will aggregate all your "module" projects
UI artifacts like HTML, JS, JSPs, etc plus java code which uses web application contexts like controllers, servlet filters etc should be included in the eclipse web project
In the eclipse web project's java build path, but the module "projects" as "required" projects
In the eclipse web project's deployment assembly, add module "projects" as dependencies.
now when you build-all and deploy the web app, all depending module projects will compile and deploy as well, but more importantly, all project functionality will be divided into seperate modular projects
setup dependencies between projects with care, so as not to introduce cyclic dependencies
dont be afraid to refactor project structure when needed to maintain clean and relevant modules
For your modules to publish their own configuration (and your main application to detect them automatically), you can, in your main applicationContext.xml, import other context.xml files from the classpath using a pattern with wildcards :
<import resource="classpath*:conf/moduleContext.xml" />
This tells spring to find and read files in all jars that match conf/moduleContext.xml.
Note there is a little limitation to this : you must have your context files in at least one directory (not in the root of the classpath). This is why in my example you have de "conf" directory.

Resources