无法找到javac编译器 [英] Unable to find a javac compiler

查看:116
本文介绍了无法找到javac编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打包使用Ant我的web应用程序,WAR文件。

I am trying to package my web application into war file using Ant.

当我建,我收到以下错误:

When I build, I am getting the following error:

C:\Documents and Settings\Administrator\workspace\Assignment7\build.xml:67: 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\Java\jre6"

以下是我的build.xml

The following is my build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="Generate War" default="install" basedir=".">


    <property name="build.dir" value="build"/>
    <property name="dir.name" value="Assignment7"/>
    <property name="package.name" value="${dir.name}.war"/>

    <property name="content" value="webContent"/>
    <property name="web-inf" value="${content}\WEB-INF"/>
    <property name="meta-inf" value="${content}\META-INF"/>
    <property name="jsp.dir.name" value="${content}"/>

    <property name="lib" value="${web-inf}\lib"/>
    <property name="src" value="src"/>
    <property name="dest.dir" value="target"/>

    <!-- Setting path to the server webapp folder -->

    <property name="webapp.dir" value="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps"/>

    <!--  Using temp folder for convinence -->

    <property name="temp.dir" value="temp"/>
    <property name="temp.dir.web-inf" value="${temp.dir}\WEB-INF"/>
    <property name="temp.dir.meta-inf" value="${temp.dir}\META-INF"/>
    <property name="temp.dir.lib" value="${temp.dir.web-inf}\lib"/>
    <property name="temp.dir.classes" value="${temp.dir.web-inf}\classes"/>
    <!--<property name="temp.dir.classes.dir" value="${temp.dir.classes}\**"/>-->

    <property name="package.file" value="${dest.dir}\${package.name}"/>

    <path id="build.class.path">
        <fileset dir="${lib}">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    <path id="build.class.path1">
        <fileset dir="C:\program files\java\jre6\lib">
            <include name="**/*.jar"/>
        </fileset>

    </path>

    <target name="clean">
        <delete>
            <fileset dir="${dest.dir}" includes="**/*"/>
        </delete>
        <delete dir="${temp.dir}"/>
        <delete dir="${temp.dir.classes}"/>
        <delete dir="${temp.dir.web-inf}"/>
        <delete dir="${temp.dir.meta-inf}"/>
    </target>


    <target name="prepare" depends="clean">
        <mkdir dir="${dest.dir}"/>
        <mkdir dir="${temp.dir}"/>
        <mkdir dir="${temp.dir.web-inf}"/>
        <mkdir dir="${temp.dir.lib}"/>
        <mkdir dir="${temp.dir.classes}"/>
        <mkdir dir="${temp.dir.meta-inf}"/>
    </target>

    <target name="compile" depends="prepare">
        <echo>==="complie"===</echo>
        <javac srcdir="${src}" destdir="${temp.dir.classes}" debug="on">
            <classpath refid="build.class.path"></classpath> 
        </javac>
        <!--<copydir src="${build.dir}\classes" dest="${temp.dir.classes}"/>-->
    </target>

    <target name="package" depends="compile">
        <echo>"PACKAGING THE FILES"</echo>
            <copy file="${meta-inf}\MANIFEST.MF" tofile="${temp.dir.meta-inf}\MANIFEST.MF" overwrite="true"/>
            <copy file="${web-inf}\web.xml" tofile="${temp.dir.web-inf}\web.xml" overwrite="true"/>
            <copy file="${web-inf}\tiles.xml" tofile="${temp.dir.web-inf}\tiles.xml" overwrite="true"/>
            <copy todir="${temp.dir.classes}">
                <fileset dir="${src}">
                    <include  name="**/*.xml"/>
                </fileset>
            </copy>

            <war destfile="${package.file}" webxml="${temp.dir.web-inf}\web.xml" basedir="${temp.dir}">
                <fileset dir="${jsp.dir.name}"/>
                <lib dir="${lib}"></lib>
                <classes dir="${temp.dir.classes}"></classes>
            </war>
    </target>

    <target name="jsps">
            <copy todir="${webapp.dir}\${dir.name}">
                <fileset dir="${content}">
                    <include name="**/*.jsp"/>
                    <include name="**/*.html"/>
                    <include name="**/*.css"/>
                    <include name="**/*.gif"/>
                    <include name="**/*.jpg"/>
                    <include name="**/*.png"/>
                    <include name="**/*.js"/>
                </fileset>
            </copy>
    </target>

    <target name="install" depends="package">
            <copy file="${package.file}" todir="${webapp.dir}" overwrite="true"/>
    </target>

</project>

我怎么能编译没有主类的类文件?

How can I compile a class file that does not have a main class?

我如何设置类路径?

有关参考,我使用Eclipse。

For reference, I am using Eclipse.

推荐答案

您所有蚂蚁的东西会工作,除了javac任务,需要的tools.jar中,位于从JDK / lib目录罚款,JRE是不是足够这种情况下。因此从蚂蚁提示:无法找到javac编译器; ......

All your ant stuff will work fine except the javac task which needs the tools.jar, located in the /lib directory from the JDK, JRE is not sufficient in that case. Therefore the hint from ant : "Unable to find a javac compiler;..."

在使用Eclipse工作的默认设置指向JRE安装。结果
所以,启动Eclipse的第一次应该是你后的第一个步骤之一:结果
窗口&GT; preferences&GT;已安装的JRE 和JRE更改设置为JDK。结果
或者使用:结果
窗口&GT; preferences&GT;蚂蚁&GT;运行&GT;类路径&GT;全球条目结果,并从你的JDK / lib文件夹中添加的tools.jar

When working with Eclipse the default setting points to your JRE installation.
So, one of your first steps after starting Eclipse for the first time should be :
Window > Preferences > Installed JREs and change the settings from JRE to JDK.
Alternatively use :
Window > Preferences > Ant > Runtime > Classpath > Global Entries
and add the tools.jar from your JDK/lib folder

这篇关于无法找到javac编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆