开发者

unable to build new java spring project

开发者 https://www.devze.com 2023-02-05 10:41 出处:网络
i am trying to build a simple java spring project i got setup which contains my hibernate .hbm mappings, the POJO\'S that go with each mappings and one SimpleFormController class that looks like this:

i am trying to build a simple java spring project i got setup which contains my hibernate .hbm mappings, the POJO'S that go with each mappings and one SimpleFormController class that looks like this:

package com.jr.user.controller;

import org.springframework.web.portlet.mvc.SimpleFormController;

public class RegisterNewUser extends SimpleFormController{

}

Its empty as you can see but when i try to build it i get the following error below:

BUILD FAILED C:\Users\xxxxxxxxxxxxx\Work\Online Racing League\build.xml:45: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set

to "C:\Program Files (x86)\Java\jre6"

Total time: 237 milliseconds

Also, whats weird is that the package line on the above code is highlighted in a red underline indicating a syntax or code error and when i mouse over to that line, this is what it says:

The type javax.portlet.PortletContext cannot be resolved. It is indirectly referenced from required .class files

My build.xml looks like this:

<?xml version="1.0"?>

<project name="Online Racing League" 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="Online Racing League"/>

    <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     --> Build the application"/>
        <echo message="deploy    --> Deploy application as directory"/>
        <echo message="deploywar --> Deploy application as a WAR file"/>
        <echo message="install   --> Install application in Tomcat"/>
        <echo message="reload    --> Reload application in Tomcat"/>
        <echo message="start     --> Start Tomcat application"/>
        <echo message="stop      --> Stop Tomcat application"/>
        <echo message="list      --> 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="${deploy.path}/${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.DeployTask">
            <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>

And my build properties is looks like this:

# Ant properties for building the springapp

appserver.home=C:/Program Files/Apache Software Foundation/Tomcat 7.0
# for Tomcat 5 use $appserver.home}/server/lib
# for Tomcat 6 use $appserver.home}/lib
appserver.lib=${appserver.home}/lib/

deploy.path=${appserver.home}/webapps

tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=
tomcat.manager.password=

Whats strange is that if i do not extend SimpleFormController . the error:

The type javax.portlet.PortletContext cannot be resolved. It is indirectly referenced from required .class files

dissapears but i still fail to bui开发者_Go百科ld it with the exact same error.

im currently using eclipse IDE and tomcat 7

I have the necessary libs needed to run spring and hibernate so i cant quite figure out whats the issue.

i checked the JAVA home path and my java is installed there correctly.

Thanks in advance.


Set your JAVA_HOME to JDK like c:\Program Files\Java\jdk1.6.0_20\


It appears that your JAVA_HOME environment variable points to a JRE (Java Runtime Environment), but you need it to point to a JDK (Java Development Kit).


Ok a small update. it now build fine and i did not have to do a single thing. i just opened the project and run the build.xml on the SpringSource tool suite IDE which is another flavour of eclipse but spring based and it worked. the only thing is that the "package" line still is highlighted with an error but it still builds fine?

Very strange indeed.


Try to change your PATH environment variable. Just put the version of Java you want before the Windows directory in your PATH.

set PATH="C:\Program Files\Java\jdk1.6.0_35\bin";%PATH%

On Windows, the java executable uses the Windows Registry to locate the default version of Java to run. The copy of java.exe to run is found by using the PATH environment variable. Unless you take steps to change this, by default a copy will be found in the Windows directory. Since this copy isn't in a Java runtime directory, it locates one by looking at the registry. So, you either need to modify the registry, or put the version of Java you want before the Windows directory in your PATH.

0

精彩评论

暂无评论...
验证码 换一张
取 消