构建后,JAR文件仍然是旧版本

时间:2015-01-09 10:10:33

标签: java eclipse svn ant jar

所以我对我的Java项目进行了一些更改,然后构建了一个新的JAR文件。我将这个JAR文件上传到我的开发服务器,在使用之后我才意识到我还在使用旧版本的Java项目,因为我试图制作的所有日志标签都没有被考虑在内。

以下是我如何称呼JAR:

  

java -Dfile.encoding = iso-8859-1 -Xmx1024m -jar myproject-majauto.jar -d mydatabase

我的build.xml

<?xml version="1.0"?>
<project name="MyProject-CORE" default="prepare-release" basedir=".">

  <property name="project.dir" value="."/>
  <property file="${project.dir}/build.properties"/>
  <property file="${project.dir}/svn.properties"/>

  <property name="dist.dir" value="${project.dir}/dist"/>

  <property name="build.dir" value="${project.dir}/build"/>
  <property name="src.dir" value="${dist.dir}/${dist.type}/src"/>
  <property name="release.dir" value="${project.dir}/release"/>

    <path id="task.path">
      <fileset dir="${project.dir}/lib" includes="**/*.jar" />
    </path>

  <!-- load svn tasks -->
  <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="task.path" />


  <!-- load ant contrib tasks -->
  <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="task.path"/>


    <target name="mkdirs">
      <mkdir dir="${build.dir}" />
      <mkdir dir="${build.dir}/${dist.type}" />
        <mkdir dir="${build.dir}/${dist.type}/lib" />
      <mkdir dir="${dist.dir}" />
      <mkdir dir="${dist.dir}/${dist.type}" />      
      <mkdir dir="${dist.dir}/${dist.type}/classes" />
      <mkdir dir="${release.dir}/${dist.type}" />
    <if>
      <equals arg1="${dist.type}" arg2="local" />
      <then>
          <mkdir dir="${release.dir}/${dist.type}" />
      </then>
      <elseif>
        <equals arg1="${dist.type}" arg2="svn" />
        <then>
            <mkdir dir="${release.dir}/${dist.type}/${svn.repository.revision}" />
        </then>
      </elseif>
      <elseif>
        <equals arg1="${dist.type}" arg2="tags" />
          <then>
            <mkdir dir="${release.dir}/${dist.type}/${tag.version}" />
          </then>
      </elseif>
      <elseif>
        <equals arg1="${dist.type}" arg2="branch" />
          <then>
            <mkdir dir="${release.dir}/${dist.type}/${branch.version}" />
          </then>
      </elseif>
    </if>
    </target>

    <path id="class.path">
        <dirset dir="${build.dir}" />
      <fileset dir="${project.dir}/lib" includes="**/*.jar" />
    </path>

  <target name="clean">
    <delete dir="${build.dir}" />
    <delete dir="${dist.dir}" />
    <if>
      <equals arg1="${dist.type}" arg2="local" />
      <then>
        <delete dir="${release.dir}/local"/>
      </then>
      <elseif>
        <equals arg1="${dist.type}" arg2="svn" />
        <then>
          <delete dir="${release.dir}/svn/${svn.repository.revision}"/>
        </then>
      </elseif>
      <elseif>
        <equals arg1="${dist.type}" arg2="tags" />
          <then>
          <delete dir="${release.dir}/tags/${tag.version}"/>
          </then>
      </elseif>
      <elseif>
        <equals arg1="${dist.type}" arg2="branch" />
          <then>
          <delete dir="${release.dir}/branch/${branch.version}"/>
          </then>
      </elseif>
    </if>
  </target>

  <target name="prepare-sources" depends="clean,mkdirs">
    <if>
       <equals arg1="${dist.type}" arg2="local" />
       <then>
            <copy todir="${dist.dir}/${dist.type}">
              <fileset dir="${project.dir}" defaultexcludes="true">
                <exclude name="**/.svn/**"/>
                <exclude name="**/CVS/**"/>
                <exclude name="/build/**"/>
                <exclude name="/dist/**"/>
                <exclude name="/tests/**"/>
                <exclude name="/release/**"/>
                <exclude name="/*.log*"/>
              </fileset>
            </copy>
       </then>

       <elseif>
        <equals arg1="${dist.type}" arg2="svn" />
        <then>
            <mkdir dir="${dist.dir}/${dist.type}/src" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.repository.url}/${svn.project.name}/src" revision="${svn.repository.revision}" destPath="${dist.dir}/${dist.type}/src" />
            </svn>

            <mkdir dir="${dist.dir}/${dist.type}/lib" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.repository.url}/${svn.project.name}/lib" revision="HEAD" destPath="${dist.dir}/${dist.type}/lib" />
            </svn>

            <mkdir dir="${dist.dir}/${dist.type}/conf" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.repository.url}/${svn.project.name}/conf" revision="HEAD" destPath="${dist.dir}/${dist.type}/conf" />
            </svn>
        </then>
       </elseif>
       <elseif>
        <equals arg1="${dist.type}" arg2="tags" />
        <then>
            <echo message="prepare svn source for compilation" />
            <echo message="svn url = ${svn.tags.url}" />
            <echo message="svn tag version = ${tag.version}" />
            <echo message="project name = ${svn.project.name}" />

            <mkdir dir="${dist.dir}/${dist.type}/src" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.tags.url}/${tag.version}/${svn.project.name}/src" revision="HEAD" destPath="${dist.dir}/${dist.type}/src" />
            </svn>

            <mkdir dir="${dist.dir}/${dist.type}/lib" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.tags.url}/${tag.version}/${svn.project.name}/lib" revision="HEAD" destPath="${dist.dir}/${dist.type}/lib" />
            </svn>

            <mkdir dir="${dist.dir}/${dist.type}/conf" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.tags.url}/${tag.version}/${svn.project.name}/conf" revision="HEAD" destPath="${dist.dir}/${dist.type}/conf" />
            </svn>
        </then>
       </elseif>
       <elseif>
        <equals arg1="${dist.type}" arg2="branch" />
        <then>
            <echo message="prepare svn source for compilation" />
            <echo message="branches url = ${svn.branches.url}" />
            <echo message="branch version = ${branch.version}" />
            <echo message="project name = ${svn.project.name}" />

            <mkdir dir="${dist.dir}/${dist.type}/conf" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.branches.url}/${branch.version}/${svn.project.name}/conf" revision="HEAD" destPath="${dist.dir}/${dist.type}/conf" />
            </svn>

            <mkdir dir="${dist.dir}/${dist.type}/src" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.branches.url}/${branch.version}/${svn.project.name}/src" revision="HEAD" destPath="${dist.dir}/${dist.type}/src" />
            </svn>

            <mkdir dir="${dist.dir}/${dist.type}/lib" />
            <svn username="${svn.repository.user}" password="${svn.repository.passwd}">
              <checkout url="${svn.branches.url}/${branch.version}/${svn.project.name}/lib" revision="HEAD" destPath="${dist.dir}/${dist.type}/lib" />
            </svn>
        </then>
       </elseif>

       <else>
         <echo message="The value of property dist.type (${dist.type} is incorrect" />
       </else>
    </if>
  </target>

    <target name="compile" depends="clean,mkdirs,prepare-sources">
      <echo>dist type is ${dist.type}</echo>
        <javac classpathref="class.path" debug="true" srcdir="${src.dir}" 
          destdir="${dist.dir}/${dist.type}/classes" target="1.5"/>
      <copy todir="${dist.dir}/${dist.type}/classes">
        <fileset dir="${src.dir}" defaultexcludes="false">
          <exclude name="**/*.java"/>
          <exclude name="**/.svn/**"/>
          <exclude name="**/CVS/**"/>
        </fileset>
      </copy>
      <copy todir="${build.dir}/${dist.type}">
        <fileset dir="${dist.dir}/${dist.type}/conf" defaultexcludes="false">
          <exclude name="**/.svn/**"/>
          <exclude name="**/CVS/**"/>
          <exclude name="applicationContext-batch.xml"/>
          <exclude name="dataSource.xml"/>
          <exclude name="requests.properties"/>
        </fileset>
      </copy>
      <copy todir="${build.dir}/${dist.type}/lib">
        <fileset dir="${dist.dir}/${dist.type}/lib" defaultexcludes="false">
          <exclude name="/buildtime/**"/>
          <exclude name="/test/**"/>
          <exclude name="**/.svn/**"/>
          <exclude name="**/CVS/**"/>
        </fileset>
      </copy>
    </target>

    <target name="package-jar" depends="compile">
    <tstamp>
        <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
      </tstamp>
        <jar destfile="${build.dir}/${dist.type}/myproject-majauto.jar" compress="true">
            <fileset dir="${dist.dir}/${dist.type}/classes" excludes="**/custom*,**/*Test*" defaultexcludes="false" />
          <fileset dir="${dist.dir}/${dist.type}/src" excludes="**/custom*,**/*Test*">
              <include name="/sql/*"/>
            <include name="/resources/*"/>
          </fileset>
          <fileset dir="${dist.dir}/${dist.type}/conf" excludes="**/custom*,**/*Test*">
          <include name="applicationContext-batch.xml"/>
          <include name="dataSource.xml"/>
          <include name="requests.properties"/>
          </fileset>

      <manifest>
        <attribute name="Main-Class" value="fr.caf.myproject.run.RunUpdateBatch" />
        <attribute name="Class-Path" value=". lib/runtime/hibernate/ehcache-1.3.0.jar lib/runtime/hibernate/hibernate3.jar lib/runtime/jakarta-commons/commons-cli-1.1.jar lib/runtime/jakarta-commons/commons-collections.jar lib/runtime/jakarta-commons/commons-lang.jar lib/runtime/jdbc/mysql-connector-java-5.1.13-bin.jar lib/runtime/jakarta-commons/commons-logging.jar lib/runtime/log4j/log4j-1.2.16.jar lib/runtime/mail/mail.jar lib/runtime/pdf/iText-5.0.5.jar lib/runtime/spring/spring.jar" />

        <attribute name="Built-By" value="Sopra Group"/>
          <section name="myproject-MAJAuto">
                <attribute name="Specification-Title" value="myproject-MAJ Automatique"/>
                <attribute name="Specification-Version" value="V1"/>
                <attribute name="Specification-Vendor" value="C2R"/>
              <attribute name="Implementation-Version" value="${tag.version}"/> 
              <attribute name="Build-Date" value="${TODAY}"/> 
                <attribute name="Implementation-Vendor" value="Sopra Group"/>
            </section>
       </manifest>
        </jar>
    </target>

    <target name="prepare-release" depends="package-jar">
      <echo>release is generated</echo>


    <if>
      <equals arg1="${dist.type}" arg2="local" />
      <then>
          <property name="zip.dir" value="${release.dir}/${dist.type}/"/>
      </then>
      <elseif>
      <equals arg1="${dist.type}" arg2="svn" />
      <then>
        <property name="zip.dir" value="${release.dir}/${dist.type}/${svn.repository.revision}"/>
      </then>
      </elseif>
      <elseif>
        <equals arg1="${dist.type}" arg2="tags" />
          <then>
            <property name="zip.dir" value="${release.dir}/${dist.type}/${tag.version}"/>
          </then>
      </elseif>
      <elseif>
        <equals arg1="${dist.type}" arg2="branch" />
          <then>
            <property name="zip.dir" value="${release.dir}/${dist.type}/${branch.version}"/>
          </then>
      </elseif>
    </if>
      <echo>directory of files: ${zip.dir}</echo>

    <zip destfile="${zip.dir}/myproject-majauto.zip">
      <fileset dir="${build.dir}/${dist.type}/" includes="**" />
    </zip>
    <delete dir="${build.dir}" />
    <delete dir="${dist.dir}" />
    </target>

</project>

我必须承认我不知道我做错了什么,仍然是java build / compil的初学者。那可能是什么错?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

看起来某些资源正在锁定jar文件。 Trey重新启动你的开发服务器。