#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    THE IMPORT org.apache.commons.logging.Log cannot be resolved.


    Hi there everyone,
    I am trying to build a Spring MVC application I have some problem when I try to include the following classes:

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    1) I am trying to build my first Spring MVC application.
    2) This application is being built with the help of Ant build script.
    3) While trying to compile the HelloController.java servlet, I find that the IDE gives the error that it could not resolve the following packages:
    a) org.springframework.
    b) javax.servlet.
    c) org.apache.
    I have followed the steps prescribed in the tutorial: Developing a Spring Framework MVC application
    4) Which can be found in http://reference.googlecode.com/svn-history/r42/springapp-enhanced/branches/springapp-dwr/spring-mvc-step-by-step.pdf
    5) The follwing tools that I am using,
    a) apache-tomcat-5.5.30.zip
    b) spring-framework-2.5-rc1-with-dependencies.zip
    c) apache-ant-1.8.1
    6) I have tried setting the classpath too, but is still has errors.
    7) I understand that I would have to add the javax.servlet classes, but what I canít understand is that I am still getting errors despite adding the commons-logging.jar, spring.jar and spring-webmvc.jar to the application classpath as you can see from the directory structure(refer to attached jpg files for more info).
    Code:
    package springapp.web;
    import org.springframework.web.servlet.mvc.Controller;
    import org.springframework.web.servlet.ModelAndView;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import java.io.IOException;
    
    public class HelloController implements Controller {
        protected final Log logger = LogFactory.getLog(getClass());
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
                            throws ServletException, IOException {
               logger.info("Returning hello view");
               return new ModelAndView("hello.jsp");
    }
    }
    Thank you in advance to everyone.
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    It would help to know what is in your ant build.xml file. Generally you'll add Jar files to the classpath element of your javac. But I'm a bit confused about what you're trying to do because you also mention an IDE. Are you using ant from within the IDE to do the build?

    Either way, we need some more information about your build file to help.

    And I know that it may not make sense but the Apache forum is for questions related to Apache httpd, not any Apache product.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0
    Yes, I used Eclipse and the ANT file was built by using functions in it. The build file is in this path: /springapp/build.xml .Here are build file contents:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <project name="springapp" basedir="." default="usage">
      <property file="build.properties"/>
      <property name="src.dir" value="src"/>
      <property name="web.dir" value="war"/>
      <property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
      <property name="name" value="springapp"/>
      <path id="master-classpath">
        <fileset dir="${web.dir}/WEB-INF/lib">
          <include name="*.jar"/>
        </fileset>
        <!-- We need the servlet API classes: -->
    <!-- * for Tomcat 5/6 use servlet-api.jar -->
    <!-- * for other app servers - check the docs -->
        <fileset dir="${appserver.lib}">
          <include name="servlet*.jar"/>
        </fileset>
        <pathelement path="${build.dir}"/>
      </path>
      <target name="usage">
        <echo message=""/>
        <echo message="${name} build file"/>
        <echo message="-----------------------------------"/>
        <echo message=""/>
        <echo message="Available targets are:"/>
        <echo message=""/>
        <echo message="build --&gt; Build the application"/>
        <echo message="deploy --&gt; Deploy application as directory"/>
        <echo message="deploywar --&gt; Deploy application as a WAR file"/>
        <echo message="install --&gt; Install application in Tomcat"/>
        <echo message="reload --&gt; Reload application in Tomcat"/>
        <echo message="start --&gt; Start Tomcat application"/>
        <echo message="stop --&gt; Stop Tomcat application"/>
        <echo message="list --&gt; List Tomcat applications"/>
        <echo message=""/>
      </target>
      <target name="build" description="Compile main source tree java files">
        <mkdir dir="${build.dir}"/>
        <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true">
          <src path="${src.dir}"/>
          <classpath refid="master-classpath"/>
        </javac>
      </target>
      <target name="deploy" depends="build" description="Deploy application">
        <copy todir="${deploy.path}/${name}" preservelastmodified="true">
          <fileset dir="${web.dir}">
            <include name="**/*.*"/>
          </fileset>
        </copy>
      </target>
      <target name="deploywar" depends="build" description="Deploy application as a WAR file">
        <war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
          <fileset dir="${web.dir}">
            <include name="**/*.*"/>
          </fileset>
        </war>
        <copy todir="${deploy.path}" preservelastmodified="true">
          <fileset dir=".">
            <include name="*.war"/>
          </fileset>
        </copy>
      </target>
      <!-- ============================================================== -->
    <!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
    <!-- ============================================================== -->
      <path id="catalina-ant-classpath">
    <!-- We need the Catalina jars for Tomcat -->
    <!-- * for other app servers - check the docs -->
        <fileset dir="${appserver.lib}">
          <include name="catalina-ant.jar"/>
        </fileset>
      </path>
      <taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
        <classpath refid="catalina-ant-classpath"/>
      </taskdef>
      <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
        <classpath refid="catalina-ant-classpath"/>
      </taskdef>
      <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
        <classpath refid="catalina-ant-classpath"/>
      </taskdef>
      <taskdef name="start" classname="org.apache.catalina.ant.StartTask">
        <classpath refid="catalina-ant-classpath"/>
      </taskdef>
      <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
        <classpath refid="catalina-ant-classpath"/>
      </taskdef>
      <target name="install" description="Install application in Tomcat">
        <install url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}" war="${name}"/>
      </target>
      <target name="reload" description="Reload application in Tomcat">
        <reload url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/>
      </target>
      <target name="start" description="Start Tomcat application">
        <start url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/>
      </target>
      <target name="stop" description="Stop Tomcat application">
        <stop url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/>
      </target>
      <target name="list" description="List Tomcat applications">
        <list url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}"/>
      </target>
      <!-- End Tomcat tasks -->
    </project>
  6. #4
  7. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    The ant build file is expecting all of your libraries to reside in the "war/WEB-INF/lib" directory. Are they there?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0
    [/IMG]Yes, I have added them under the following directory:
    /springapp/war/WEB-INF/lib/commons-logging.jar
    /springapp/war/WEB-INF/lib/spring.jar
    /springapp/war/WEB-INF/lib/spring-webmvc.jar

    Whereas the HelloController is in:
    /springapp/src/springapp/web/HelloController.java

    I wish I know how to use the feature to insert a file. I could append a picture of the Directory structure.

    Thank you for your patience,

    Btw, my environ settings:
    ANT_HOME
    C:\Documents and Settings\C1272E\My Documents\SPRING STEP-BY-STEP\INSTALLERS FOR DEVELOPMENT\apache-ant-1.8.1

    CATALINA_HOME
    C:\Documents and Settings\C1272E\apache-tomcat-5.5.30


    CLASSPATH
    .;C:\Program Files\Java\jdk1.6.0_21\lib;C:\Documents and Settings\C1272E\apache-tomcat-5.5.30\common\lib;C:\Documents and Settings\C1272E\apache-tomcat-5.5.30\common\lib\servlet-api.jar

    JAVA_HOME C:\Program Files\Java\jdk1.6.0_21

    Path
    D:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;% SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Windows Imaging\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Documents and Settings\C1272E\My Documents\SPRING STEP-BY-STEP\INSTALLERS FOR DEVELOPMENT\apache-ant-1.8.1\bin
    Last edited by ROBINSON83; August 18th, 2010 at 06:02 AM. Reason: adding more details.

IMN logo majestic logo threadwatch logo seochat tools logo