按照http://www.csdn.net/develop/article/19/19397.shtm作的,我的build.xml是这样的
-------------build.xml----------------
<?xml version="1.0" encoding="GB2312" ?>
<project name="creditSys" default="run">
    <property name="src" location="src" />
    <property name="build" location="build" />
    <property name="build.classes" location="build/classes" />
    <property name="jdo.home" value="../../jdogenie-2.0.1"/>
    <property name="jdo.project" value="creditSys.jdogenie"/>
    <property name="jdo.lib" value="${jdo.home}/lib"/>
    <property name="jdo.tools" value="${jdo.home}/tools"/>
    <property name="jdo.license" value="${jdo.home}/license"/>
    <property name="jdbc.jar" location="../../mysql/lib/mm.mysql-2.0.4-bin.jar" />    <path id="cp">
        <pathelement path="${build.classes}"/>
        <pathelement path="${jdbc.jar}"/>
        <pathelement path="${jdo.license}"/>
        <fileset dir="${jdo.lib}" includes="*.jar"/>        <fileset dir="." includes="*.jar" />
    </path>    <target name="cleanup" description="清除所有编译生成的class文件">
        <delete>
            <fileset dir="${build.classes}" includes="**/*.class"/>
        </delete>
    </target>    <target name="compile">
        <javac debug="true" destdir="${build.classes}" srcdir="${src}" classpathref="cp"/>
    </target>    <target name="enhance" depends="cleanup, compile">
        <taskdef classpathref="cp" resource="jdogenie.tasks"/>
        <jdo-enhance project="${ant.project.name}.jdogenie" outputdir="${build.classes}" >
        <persistentaware dir="${build.classes}">
            <package name="jdogenie.*"/>
        </persistentaware>
        </jdo-enhance>
    </target>
    
    <target name="run" depends="enhance" description="Run the application">
        <java classname="jdogenie.Main" classpathref="cp" />
          
    </target></project>
----------------------------------------------------------
按照上面的build.xml用ant来运行,都没有问题,用java运行就不行。试了n种classpath了,总说java.lang.NullPointerException,不知道用java来运行应该怎么写命令行

解决方案 »

  1.   

    程序有问题吗?怎么用ant好用啊,数据都写入数据库了,而且这不是我写的阿,是按照上面那个地址的源代码阿,只是改了包名
    -------------------jdogenie.Main----------------------------
    package jdogenie;import javax.jdo.*;
    import java.util.*;
    import java.io.IOException;public class Main {    public static void main(String[] args) throws Exception {
            System.out.println("开始测试功能……");        inputCard("张三","东风东路311号","223003433995431237","020-38864157",500.00f,5000.0f);
            System.out.println("信用卡已创建!");    }    /**
         * 本方法专用于获取JDO API的核心对象:存储管理器PersistenceManager
         */
        public static PersistenceManager getPersistenceManager() {
            if(pmf == null) {
                java.util.Properties p = new java.util.Properties();
                try {
                    //从配置文件读入配置信息
                    p.load(Main.class.getClassLoader().getResourceAsStream("/creditSys.jdogenie"));            } catch(IOException ex) {
                    throw new RuntimeException(ex);
                }
                pmf = JDOHelper.getPersistenceManagerFactory(p);
            }        return pmf.getPersistenceManager();
        }
        private static PersistenceManagerFactory pmf;public static CreditCard inputCard(
            String name,
            String address,
            String idcard,
            String phone,
            float initialBalance,
            float allowOverDraft
        ) throws IdCardDuplicatedException {        CreditCard cc = new CreditCard();
            cc.setName(name);
            cc.setAddress(address);
            cc.setIdcard(idcard);
            cc.setPhone(phone);
            cc.setInitialBalance(initialBalance);
            cc.setAllowOverDraft(allowOverDraft);        //以下是自动产生的信息:
            cc.setCreateTime(new Date());
            cc.setBalance(initialBalance); //使刚创建后的余额等于初始余额,这是典型的业务逻辑        //下面将新信用卡保存到数据库,注意其中的JDO API。
            PersistenceManager pm = getPersistenceManager();
            //先检测是否已经有该身份证注册的信用卡存在:
            Query q = pm.newQuery(CreditCard.class,"idcard==_newIdcard");
            q.declareParameters("String _newIdcard");
            Collection existCards = (Collection)q.execute(idcard);
            if(existCards.iterator().hasNext()) {
                throw new IdCardDuplicatedException(); //已经该身份证号存在
            }        //身份证号没重复,以下保存该信用卡对象:
            pm.currentTransaction().begin(); //每次对数据库的更新必须放到事务中
            pm.makePersistent(cc);
            pm.currentTransaction().commit(); //提交新对象
            pm.close(); //释放JDO资源        return cc;
        }    public static class IdCardDuplicatedException extends RuntimeException {}}
    ----------------------------------------------------