views:

1373

answers:

3

I have a standard (I think) web project developed with the eclipse IDE. I wish to port it to Intellij idea 8.1 - I think that, among other things, it has better taglib support.

My project structure is as follows:

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 can't seem to get this project configured with my local tomcat server (version: apache-tomcat-6.0.18).

I think that a good answer would be a standard, step by step, cookbook answer as to how to port (and perhaps how to correctly define a tomcat web application within intellij idea).

Thanks all!

A: 
  1. By default, log4j will look for it's configuration file (either log4j.xml or log4j.properties) from the classpath of your application. So this means you should place it in WEB-INF\classes, or you can specify a different location with the environment variable log4j.configuration. See the log4j manual.
  2. What IDE you use should have no impact on the structure of your application when it gets deployed to your servlet container. It sounds like maybe you were relying on Eclipse to package the files in a specific way - this is probably a bad practice. Are you using an actual build script?
matt b
Despite having a build.xml file for creation of a .war file (for production purposes) I had relied on eclipse to deploy an exploded web application to a local tomcat server...
Yaneeve
I wouldn't really suggest that as a bad practice - you are relying on the way the IDE will deploy it; better to have that packaging be a strict part of the build script.
matt b
+1  A: 

I think the first step would be to create a stand-alone build file which will produce a WAR. Do this before attempting to import the project into InteliJ.

I would use Maven. Creating a maven POM file to create a WAR is almost trivial and you can easily override the the default locations for your src, conf, and web content to match you existing src directory. Then test the build by deploying your newly Maven created WAR to Tomcat. I wouldn't think this first task would take more than a half day (at most a full day).

IntelliJ has a built in utility to import Maven projects. Then you should be off and running....

Regardless of the IDE you finally settle on, your project will be much better off in the long run for the Maven migration.

You 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"&gt;
  <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&lt;/url&gt;
  <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 an example POM only... It's just meant to get you started and may not work "as is".

Vinnie
I've just gotten introduced to maven myself and I think that it is pretty neat. But is there no standard way? Is there no fixed directory structure that is immutable to IDEs?
Yaneeve
Not that I know of. Every team and every IDE seems to do things a little different. I try to steer my teams to follow Maven's conventions so we don't been to override anyhting, but it's really more personal preference.
Vinnie
+1  A: 

Start off by creating an empty web application for tomcat, within IntelliJ - and make sure that it deploys correctly This will produce a directory structure that you should then be able to copy your source files/web assets into.

The thing that you'll probably need to handle differently is the lib files - don't store these directly in the WEB-INF directory, as keeping them in a separate 'library' area, and allowing the IDE to include them in the WAR at build time is generally a better approach, as it promotes re-use across projects.

The key thing to aim for is to not try to set your project up to completely mirror a tomcat application, as the build process will pull together the various parts for you. It all breaks down into 3 sections...

  1. Static assets - images, config files and jsp files (Ok, I know JSP files are kinda dynamic)
  2. Java classes - source code that you write yourself (The IDE will compile these and place them in the appropriate location)
  3. Java Libraries - third party code that you compile against (Again the IDE will place these in the appropriate location)

There are a few bits of configuration, within the project file, that you'll need to tweak to suit your needs, but it's generally straightforward.

belugabob