Java 1.5 を使用する必要がある古いプロジェクトに取り組んでいますが、ビルド スクリプトを実行すると、次のエラーが発生します。
java.lang.UnsupportedClassVersionError: Bad version number in .class file
このエラーは、Java 1.5 のみを使用したいのに、新しいバージョンの Java が使用されていることを示していると思います。両方が を指すように、下Windows->Preferences->Java->Installed JREs
と下の設定を変更しました。の下に、変数を追加し、古いバージョンの Javaを指すようにしました。この行をビルド スクリプトに追加すると、次のようになります。Run As->External Tool Configuration->JRE
Java 1.5
Run As->External Tool Configuration->Environment
JAVA_HOME
JRE_HOME
<echo message="ant.java.version: ${ant.java.version}"/>
Eclipse は次の値を返します。
[echo] ant.java.version: 1.5
しかし、上記のエラーはまだ存在しています。プロジェクトをビルドする唯一の方法は、my変数JAVA_HOME
とJRE_HOME
環境変数を変更して、古いバージョンの Java を指すようにすることです。システム環境変数を変更せずにプロジェクトをビルドするために変更できる Eclipse の設定は他にありますか? (つまり、Ant は Java 1.5 を使用してプロジェクトをビルドしますが、システム変数は依然として Java 1.7 を指しています)。
のコードbuild.xml
:
<project name="osd-bits" basedir="." default="deploy">
<!-- Project settings -->
<!-- TODO -->
<!-- This needs to be set individually by each developer to the correct Tomcat path -->
<property name="tomcat.path" value="C:\Tomcat 6\apache-tomcat-6.0.35" />
<property name="project.title" value="OSD BITS"/>
<property name="project.name" value="osd-bits"/>
<property name="project.version" value="2.0"/>
<property name="project.deploypath" value="${tomcat.path}\\webapps"/>
<property name="project.workdir" value="${tomcat.path}\\work\Catalina\localhost"/>
<!-- Test Server Settings -->
<property name="project.deploypathtest" value="T:\Program Files\jakarta-tomcat-5.0.28\webapps"/>
<property name="project.workdirtest" value="T:\Program Files\jakarta-tomcat-5.0.28\work\Catalina\localhost"/>
<!-- Staging Server Settings -->
<property name="project.deploypathstage" value="S:\Program Files\jakarta-tomcat-5.0.28\webapps"/>
<property name="project.workdirstage" value="S:\Program Files\jakarta-tomcat-5.0.28\work\Catalina\localhost"/>
<!-- Production Server Settings -->
<property name="project.deploypathprod" value="P:\Program Files\jakarta-tomcat-5.0.28\webapps"/>
<property name="project.workdirprod" value="P:\Program Files\jakarta-tomcat-5.0.28\work\Catalina\localhost"/>
<!-- Path settings -->
<property name="path.binary" value="${basedir}/../../baja2/bin"/>
<property name="path.webroot" value="${basedir}/webroot"/>
<property name="path.conf" value="${basedir}/conf"/>
<property name="path.src" value="${basedir}/src"/>
<property name="path.build" value="${basedir}/bin"/>
<property name="path.cmdlib" value="${basedir}/cmd/lib"/>
<property name="path.buildlib" value="${tomcat.path}\\lib"/>
<property name="path.webinf" value="${path.webroot}/WEB-INF"/>
<property name="path.lib" value="${path.webinf}/lib"/>
<property name="path.classes" value="${path.webinf}/classes"/>
<property name="path.classpath" value="${path.lib}/baja.jar;
${path.lib}/struts.jar;
${path.buildlib}/fop.jar;
${basedir}/lib/servlet.jar;
${path.buildlib}/velocity-dep-1.4.jar;
${basedir}/lib/jxl.jar;
${path.lib}/display.jar;
${path.buildlib}/commons-validator.jar;
${path.buildlib}/commons-beanutils.jar;
${path.lib}/quartz-1.6.3.jar"/>
<!-- Check timestamp on files -->
<target name="timecheck">
<tstamp/>
</target>
<!-- Remove classes for clean build -->
<target name="clean" description="Prepare for clean build">
<delete dir="${path.build}/com"/>
<delete file="${path.lib}/${project.name}.jar"/>
<delete file="${path.lib}/${project.name}-config.jar"/>
</target>
<!-- jar up config files -->
<target name="config">
<jar jarfile="${path.lib}/${project.name}-config.jar" basedir="${path.conf}"/>
</target>
<!-- Full build of java and config files-->
<target name="build" depends="timecheck,clean,config">
<echo message="ant.java.version: ${ant.java.version}" />
<javac srcdir="${path.src}" destdir="${path.build}" classpath="${path.classpath}" debug="true" target="1.5" includeantruntime="false"/>
<jar jarfile="${path.lib}/${project.name}.jar" basedir="${path.build}"/>
</target>
<!-- Builds everything in src directory and deploys .war to deployment directory -->
<target name="deploy" depends="build" description="Deploys project to deployment directory">
<delete file="${project.deploypath}\${project.name}.war"/>
<delete dir="${project.deploypath}\${project.name}"/>
<delete dir="${project.workdir}\${project.name}"/>
<copy todir="${project.deploypath}\${project.name}">
<fileset dir="${path.webroot}"/>
</copy>
</target>
<!-- Builds everything in src directory and deploys to test server deployment directory -->
<target name="deploytotest" depends="build" description="Deploys project to test deployment directory">
<delete file="${project.deploypathtest}\${project.name}.war"/>
<delete dir="${project.deploypathtest}\${project.name}"/>
<delete dir="${project.workdirtest}\${project.name}"/>
<copy todir="${project.deploypathtest}\${project.name}">
<fileset dir="${path.webroot}"/>
</copy>
</target>
<!-- Builds everything in src directory and deploys to staging server deployment directory -->
<target name="deploytostage" depends="build" description="Deploys project to stage deployment directory">
<delete file="${project.deploypathstage}\${project.name}.war"/>
<delete dir="${project.deploypathstage}\${project.name}"/>
<delete dir="${project.workdirstage}\${project.name}"/>
<copy todir="${project.deploypathstage}\${project.name}">
<fileset dir="${path.webroot}"/>
</copy>
</target>
<!-- Builds everything in src directory and deploys to production server deployment directory -->
<target name="deploytoprod" depends="build" description="Deploys project to production deployment directory">
<delete file="${project.deploypathprod}\${project.name}.war"/>
<delete dir="${project.deploypathprod}\${project.name}"/>
<delete dir="${project.workdirprod}\${project.name}"/>
<copy todir="${project.deploypathprod}\${project.name}">
<fileset dir="${path.webroot}"/>
</copy>
</target>
<target name="movejsps" description="Moves all JSP files without doing a complete rebuild">
<copy todir="${project.deploypath}\${project.name}\jsp" preservelastmodified="false" >
<fileset dir="${path.webroot}/jsp" />
</copy>
</target>
<target name="movejs" description="Moves all JS files without doing a complete rebuild">
<copy todir="${project.deploypath}\${project.name}\js" preservelastmodified="false" >
<fileset dir="${path.webroot}/js" />
</copy>
</target>
<target name="movecss" description="Moves all CSS files without doing a complete rebuild">
<copy todir="${project.deploypath}\${project.name}\css" preservelastmodified="false" >
<fileset dir="${path.webroot}/css" />
</copy>
</target>
<target name="movetemplates" description="Moves all Report Template files without doing a complete rebuild">
<copy todir="${project.deploypath}\${project.name}\templates" preservelastmodified="false" >
<fileset dir="${path.webroot}/templates" />
</copy>
</target>
<target name="copyjar" description="Moves latests baja.jar into demos webinf lib">
<copy file="${path.binary}/baja.jar" todir="${path.lib}" preservelastmodified="true" />
</target>
<!-- Builds the command line distribution -->
<target name="deploycmd" depends="build" description="Deploys project to test deployment directory">
<delete file="${path.cmdlib}\${project.name}.jar"/>
<delete file="${path.cmdlib}\${project.name}-config.jar"/>
<copy file="${path.lib}/${project.name}.jar" todir="${path.cmdlib}" preservelastmodified="true" />
<copy file="${path.lib}/${project.name}-config.jar" todir="${path.cmdlib}" preservelastmodified="true" />
</target>