java - 无法构建新的java spring项目

标签 java spring ant build

我正在尝试构建一个简单的 java spring 项目,我进行了设置,其中包含我的 hibernate .hbm 映射、与每个映射一起使用的 POJO 以及一个如下所示的 SimpleFormController 类:

package com.jr.user.controller;

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

public class RegisterNewUser extends SimpleFormController{

}

如您所见,它是空的,但是当我尝试构建它时,出现以下错误:

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

此外,奇怪的是上面代码中的包行以红色下划线突出显示,表示语法或代码错误,当我将鼠标悬停到该行时,这就是它所说的:

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

我的 build.xml 如下所示:

<?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>

我的构建属性如下所示:

# 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=

奇怪的是,如果我不扩展 SimpleFormController 。错误:

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

消失了,但我仍然无法构建它,并出现完全相同的错误。

我目前使用 eclipse IDE 和 tomcat 7

我有运行 spring 和 hibernate 所需的必要库,所以我不太清楚问题出在哪里。

我检查了 JAVA 主路径,我的 java 已正确安装在那里。

提前致谢。

最佳答案

将您的JAVA_HOME设置为JDK,例如c:\Program Files\Java\jdk1.6.0_20\

关于java - 无法构建新的java spring项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4722873/

相关文章:

java - Java 中的生产者/消费者。为什么我们需要两个条件?

java - AndroidAnnotations Rest SourceHttpMessageConverter错误

java - RabbitListener 不会接收使用 AsyncRabbitTemplate 发送的每条消息

java - Spring 在服务器上运行良好,但在主应用程序上运行不佳

java - 如何使用 ProcessBuilder (Java) 获取 Ant 构建的状态

java - WeakReferenced 对象在调用 System.gc() 后未被垃圾回收

java - Spring 5.1.2 PathMatchingResourcePatternResolver 检测 jar 根目录上的文件

java - Spring MVC中没有参数的@RequestMapping

java - 在 evosuite 测试用例生成中使用 ProjectCP 通配符

java.io.FileNotFoundException : http://localhost:8080/manager/text/list