Porting tomcat web project from eclipse ganymede to intellij 8.1
I have a standard (I think) web project developed with the Eclipse IDE. I want to port it to Intellij 8.1 idea. I think it has better taglib support, by the way.
My project structure looks like this:
Project Folder
./src [java source files etc.]
./conf [configuration files - log4j, spring beans...]
./buid [ant files]
./WebContent
./WebContent/images [image files]
./WebContent/META-INF
./WebContent/META-INF/context.xml
./WebContent/pages [.jsp+.html files]
./WebContent/scripts [.js files]
./WebContent/skins [.css files]
./WebContent/WEB-INF
./WebContent/WEB-INF/classes [.class files]
./WebContent/WEB-INF/lib [.jar files]
./WebContent/WEB-INF/tags [.tag files]
./WebContent/WEB-INF/web.xml
I cannot setup this project on my local tomcat server (version: apache-tomcat-6.0.18).
I think a good answer would be a standard, step by step, cookbook answer on how to port (and possibly how to correctly define tomcat web app within intellij idea).
Thanks everyone!
a source to share
I think the first step would be to create a standalone assembly file that will create the WAR. Do this before attempting to import the project into InteliJ.
I would use Maven . Creating a maven POM file before creating a WAR is almost trivial and you can easily override the default locations for your src, conf and web content to match your existing src directory. Then test the build by deploying the new Maven generated WAR for Tomcat. I would not have thought that this first task would take over noon (full day maximum).
IntelliJ has a built-in utility for importing Maven projects . Then you should be off and running.
Regardless of the IDE you finally settle for, your project will be much better in the long run for Maven migration.
The initial Maven POM file will look something like this:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany.yourapp</groupId>
<artifactId>yourapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Your project name here</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
*** other dependencies here ***
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>conf</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>WebContent</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
*** This is a POM example only ... It is only intended to get you started and not be able to work "as is".
a source to share
Start by creating a blank web app for tomcat in IntelliJ - and make sure it's deployed correctly This will create a directory structure where you can copy your source files / web resources to.
What you will probably have to handle differently are the lib files - don't store them directly in the WEB-INF directory as keep them in a separate library area and let the IDE include them in the WAR at build time, usually is the best approach as it promotes reuse across projects.
The key point to pay attention to is not trying to customize the project completely to reflect the tomcat application completely, as the build process will put the different parts together for you. This is all broken down into 3 sections ...
- Static assets - images, config files and jsp files (Ok, I know JSP files are dynamic)
- Java classes are source code that you write yourself (the IDE will compile them and place them in the appropriate place)
- Java Libraries are third-party code that you compile (again the IDE will put them in the appropriate place).
There are a few bits of configuration in the project file that you need to tweak to suit your needs, but this is usually straightforward.
a source to share
- By default, log4j will look for the config file (log4j.xml or log4j.properties) from the classpath of your application. So this means you have to put it in
WEB-INF\classes
, or you can specify a different location with an environment variablelog4j.configuration
. See the log4j manual . - Which IDE you are using should not affect the structure of your application when deployed to your servlet container. It sounds like you were relying on Eclipse to package your files in a certain way - this is probably bad practice. Are you using an actual build script?
a source to share