找不到包导致编译失败

Fail to compile due to package not found

问题:在build.xml[=上使用“运行 As > Ant Build”构建失败17=]

当我尝试编译演示时java,它编译失败。附上build.xml和对应的eclipse设置。需要的包到位但仍然无法编译。

Here is the demo source code你也可以下载这个理财工具来玩玩。警告:涉及极高风险投资

<?xml version="1.0"?>
<project default="build" basedir=".">
    <property file="build.properties" />
    <property name="name" value="Login" />
    <property name="src.dir" location="${basedir}/src" />
    <property name="build" location="${basedir}/build" />
    <property name="build.classes" location="${build}/classes" />

    <target name="checkos">
        <condition property="bin.dir" value="${basedir}/../../../../bin">
          <os family="windows" />
        </condition>                      
        <condition property="bin.dir" value="${basedir}/../../../../lib">
          <os family="unix" />
        </condition>    
    </target>

    <!-- App build -->
    <target name="build" depends="checkos" description="Builds the ${name} application">
        <!-- Creating directory -->
        <mkdir dir="${build.classes}" />

        <!-- Compiling sources -->
        <javac srcdir="${src.dir}"
               destdir="${build.classes}"
               includeAntRuntime="false"
               debug="${build.debug}"
               deprecation="true"
               verbose="false"
               optimize="true"
               classpath="${bin.dir}/java/fxcore2.jar" >
        </javac>

        <!-- Creating JAR-file -->
        <jar jarfile="${build}/${name}.jar">
            <fileset dir="${build.classes}" />
            <manifest>
                <attribute name="Main-Class" value="login.Main" />
                <attribute name="Class-Path" value="fxcore2.jar" />
            </manifest>
        </jar>
    </target>

    <target name="rebuild" depends="clean, build" description="Rebuilds project" />

    <!-- Clean -->
    <target name="clean" description="Removes all temporary files">
        <!-- Deleting files -->
        <delete dir="${build}" />
    </target>

    <target name="run" depends="checkos" description="Rebuilds and run ${name}">
        <copy file="${bin.dir}/java/fxcore2.jar" tofile="${build}/fxcore2.jar" overwrite="true" />
        <java jar="${build}/${name}.jar" fork="true" failonerror='true' dir="${bin.dir}">
            <jvmarg value="-Djava.library.path=${java.library.path}${path.separator}${bin.dir}${path.separator}${bin.dir}/java" />
            <arg line="--login {LOGIN}" />
            <arg line="--password {PASSWORD}" />
            <arg line="--url http://www.fxcorporate.com/Hosts.jsp" />
            <arg line="--connection Demo" />
            <arg line="--sessionid {SESSIONID}" />
            <arg line="--pin {PIN}" />
        </java>
    </target>

</project>

错误输出如下:

Buildfile: C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\build.xml
checkos:
build:
    [javac] Compiling 3 source files to C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\build\classes
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:3: error: package fxcm.fxcore2 does not exist
    [javac] import fxcm.fxcore2.*;
    [javac] ^
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:45: error: cannot find symbol
    [javac]     private static void printAccounts(O2GSession session) throws Exception {
    [javac]                                       ^
    [javac]   symbol:   class O2GSession
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:6: error: package com.fxcore2 does not exist
    [javac] import com.fxcore2.*;
    [javac] ^
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:8: error: cannot find symbol
    [javac] public class SessionStatusListener implements IO2GSessionStatus {
    [javac]                                               ^
    [javac]   symbol: class IO2GSessionStatus
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:9: error: cannot find symbol
    [javac]     private O2GSession mSession;
    [javac]             ^
    [javac]   symbol:   class O2GSession
    [javac]   location: class SessionStatusListener
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:18: error: cannot find symbol
    [javac]     public SessionStatusListener(O2GSession session, String sSessionID, String sPin) {
    [javac]                                  ^
    [javac]   symbol:   class O2GSession
    [javac]   location: class SessionStatusListener
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:48: error: cannot find symbol
    [javac]     public void onSessionStatusChanged(O2GSessionStatusCode status) {
    [javac]                                        ^
    [javac]   symbol:   class O2GSessionStatusCode
    [javac]   location: class SessionStatusListener
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:9: error: cannot find symbol
    [javac]         O2GSession session = null;
    [javac]         ^
    [javac]   symbol:   class O2GSession
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:22: error: cannot find symbol
    [javac]             session = O2GTransport.createSession();
    [javac]                       ^
    [javac]   symbol:   variable O2GTransport
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:46: error: cannot find symbol
    [javac]         O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
    [javac]         ^
    [javac]   symbol:   class O2GResponseReaderFactory
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:50: error: cannot find symbol
    [javac]         O2GLoginRules loginRules = session.getLoginRules();
    [javac]         ^
    [javac]   symbol:   class O2GLoginRules
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:51: error: cannot find symbol
    [javac]         O2GResponse response = loginRules.getTableRefreshResponse(O2GTableType.ACCOUNTS);
    [javac]         ^
    [javac]   symbol:   class O2GResponse
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:51: error: cannot find symbol
    [javac]         O2GResponse response = loginRules.getTableRefreshResponse(O2GTableType.ACCOUNTS);
    [javac]                                                                   ^
    [javac]   symbol:   variable O2GTableType
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:52: error: cannot find symbol
    [javac]         O2GAccountsTableResponseReader accountsResponseReader = readerFactory.createAccountsTableReader(response);
    [javac]         ^
    [javac]   symbol:   class O2GAccountsTableResponseReader
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\Main.java:54: error: cannot find symbol
    [javac]             O2GAccountRow accountRow = accountsResponseReader.getRow(i);
    [javac]             ^
    [javac]   symbol:   class O2GAccountRow
    [javac]   location: class Main
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:51: error: cannot find symbol
    [javac]         case TRADING_SESSION_REQUESTED:
    [javac]              ^
    [javac]   symbol:   variable TRADING_SESSION_REQUESTED
    [javac]   location: class SessionStatusListener
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:58: error: cannot find symbol
    [javac]         case CONNECTED:
    [javac]              ^
    [javac]   symbol:   variable CONNECTED
    [javac]   location: class SessionStatusListener
    [javac] C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\src\SessionStatusListener.java:63: error: cannot find symbol
    [javac]         case DISCONNECTED:
    [javac]              ^
    [javac]   symbol:   variable DISCONNECTED
    [javac]   location: class SessionStatusListener
    [javac] 18 errors

BUILD FAILED
C:\Users\clint\Documents\programming\Projects\fxcm\java_sample\NonTableManagerSamples\Login\build.xml:31: Compile failed; see the compiler error output for details.

Total time: 1 second

使用命令行,以下命令可能有效:

ant rebuild
ant run

来自路径 C:\Program Files\CandleWorks\ForexConnectAPI\samples\java\NonTableManagerSamples\Login> 或等效路径。

附带说明一下,IntelliJ 可能是 Eclipse 的一个很好的替代品,我个人更喜欢 IntelliJ。