I'm compiling many legacy Java code probably written with Java1.3 and I got tons of errors like this:
Copydir.java:128: warning: as of release 5, 'enum' is a keyword, and may not be used as an identifier
[javac] (use -source 5 or higher to use 'enum' as a keyword)
[javac] Enumeration enum = filecopyList.keys();
It's too time consuming to replace each instance of enum with _enum so I added source="1.3" in ant javac task as below (based on examples from http://ant.apache.org/manual/Tasks/javac.html). But I still got the same compile error. I've tried to change source = 1.4,1.5, and still same error.
<javac srcdir="${src.dir}"
destdir="${build.classes}"
debug="true" debuglevel="lines,vars,source"
source="1.3"
deprecation="off"
optimize="on">
What is the right way to tell comiler that the source is written in 1.3, but I want to compile it to run in 1.6? I'm using jdk1.6.0.26 and ant 1.8.2
That's a warning, not an error. Unless there are other errors in the build that should work just fine.
Related
I reinstalled between jdk-8 and jdk-12, the building process shows different errors but both failed. And both are showing in the log that the bcel package is missing as the first error.
I've set JAVA_HOME in both jdk with the corresponding value;
sh build.sh -Ddist.dir=~/tmp/ant dist
this is the code I get from the org document for building.
Loading source files for package org.apache.tools.tar...
Loading source files for package org.apache.tools.zip...
Constructing Javadoc information...
/home/uppdev/tmp/ant/src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java:23: error: package org.apache.bcel.classfile does not exist
import org.apache.bcel.classfile.ClassParser;
^
/home/uppdev/tmp/ant/src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java:24: error: package org.apache.bcel.classfile does not exist
import org.apache.bcel.classfile.ConstantValue;
:
:
:
Building index for all the packages and classes...
Building index for all classes...
Generating /home/uppdev/tmp/ant/build/javadocs/help-doc.html...
Note: Custom tags that could override future standard tags: #todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
26 errors
100 warnings
BUILD FAILED
/home/uppdev/tmp/ant/build.xml:1012: The following error occurred while executing this line:
/home/uppdev/tmp/ant/build.xml:1520: Javadoc returned 1
Total time: 20 seconds
If this is for ant 1.10.2 then I can provide info:
JDK8 returns an error for missing references in javadocs (see https://bugs.openjdk.java.net/browse/JDK-8224266) which can be maded non-fatal by passing -Xdoclint:none to javadoc.
ant 1.10.2 removed this flag together with the configure param withDoclint which made builds fail if the optional dependencies were not found.
A workaround is to add additionalparam="-Xdoclint:none" to the <javadoc ...> tag in the <target name="javadocs" in build.xml before building.
Fixed part of 1.10.2:
<target name="javadocs" depends="check-javadoc"
description="--> creates the API documentation" unless="javadoc.notrequired">
<mkdir dir="${build.javadocs}"/>
<javadoc additionalparam="-Xdoclint:none"
useexternalfile="yes"
destdir="${build.javadocs}"
failonerror="true"
author="true"
version="true"
locale="en"
windowtitle="${Name} API"
doctitle="${Name}"
maxmemory="1000M"
verbose="${javadoc.verbose}">
I am trying to compile commit 9c8bad6ec6d51a0abfb9f6e840e2dbec3e2fbcee of the Mozilla Rhino project to make some tests on it.
I cloned the repository to my server, and checked out the hash.
I then proceeded into compiling using ant, which returned errors on lines 128, 57 and 53 of build.xml.
I'm not 100% sure of what line 127 does:
<!--<antcall target="jar-src"/>-->
So I commented it out for the time being.
For lines 53 and 57:
<target name="compile-src" depends="prepare">
<ant dir="/home/dario/testEnv/181834/prefix/rhino"/> <- line 53
</target>
<target name="compile-toolsrc" depends="prepare">
<ant dir="/home/dario/testEnv/181834/prefix/rhino"/> <- line 57
</target>
They seemed to be setting the path for compiling the path. They did so dynamically originally, with some variable, but as that didn't work I changed it and wrote the actual path.
Not when I compile it doesn't throw any errors, but it does not generate the compiled classes.
Any ideas?
That version of Rhino is ancient.
You could fix your problem by using JDK version 1.4 to compile. The problem is that that version of Rhino contained code that was incompatible with the JDK 1.5 enhancements (specifically, it attempts to use enum as a variable name).
Alternatively, you could patch the build.xml to specify the source version to be 1.4 when compiling on the appropriate javac tasks.
More realistically, do you have any option of upgrading to a reasonably recent version of Rhino?
I recently noticed Scala compiler warnings that maven was generating that looked like this:
[WARNING] warning: there were 4 deprecation warning(s); re-run with -deprecation for details
[WARNING] warning: there were 3 feature warning(s); re-run with -feature for details
[WARNING] two warnings found
It was not immediately apparent to me how to follow the warning's instructions so I could get details on how to change my code.
Just to make it clearer from Philip's answer (as specified on the plugin page), add the following to your pom.xml file:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
...
<configuration>
<args>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
</configuration>
</plugin>
It turns out that these two instructions are coming from the Scala compiler and so what needs to happen under the covers is for scalac to be called with -deprecation or -feature as described here:
http://www.scala-lang.org/files/archive/nightly/docs-2.10.3/manual/html/scalac.html
(actually I never saw the -feature option explained anywhere but I was able to specify it as follows)
I'm using the scala-maven-plugin and compiling with scala:compile described here:
http://davidb.github.io/scala-maven-plugin/compile-mojo.html
The relevant parameter is described here:
http://davidb.github.io/scala-maven-plugin/compile-mojo.html#addScalacArgs
So, two maven commands that I found helpful were:
mvn clean compile -DaddScalacArgs=-deprecation
mvn clean compile -DaddScalacArgs=-feature
Ant task breaks at the <wsejbdeploy> tag. The exception message is :
[wsejbdeploy] Error executing deployment: java.lang.ClassNotFoundException.
Error is com.ibm.etools.ejbdeploy.batch.plugin.BatchExtension.
[wsejbdeploy] java.lang.ClassNotFoundException:
com.ibm.etools.ejbdeploy.batch.plugin.BatchExtension
[wsejbdeploy] at java.lang.Class.forName(Class.java:136)
In addition to that, ivy.xml reports problems, but when I inspect it, the messages have no sense (screenshot). I suspect the problems could be:
a) Additional files that I have for the build which conflict with the upgraded Ant (in RSA 7.0 i've had Ant 1.6.5 and RSA 8.0 comes with Ant 1.7.1). Additional files are:
required for ant tasks execution
ant-contrib/ant-contrib.jar
antelope-tasks/AntelopeTasks_3.2.10.jar
antform/antform.jar
antform/defaultStyle.txt
antlr/antlr.jar
checkstyle/checkstyle-4.2.jar
checkstyle/checkstyle-optional-4.2.jar
checkstyle/checkstyle-frames-errors.xsl
clover/clover.jar
clover/cenquatasks.jar
clover/clover.license
doccheck/doccheck-modified.jar
ivy/ivy-20060723172807.jar
jakarta-commons/commons-beanutils.jar
resources/checkstyle/checks-source.xml
resources/checkstyle/checksTransformation.xsl
b) Changes in the Ant regarding EJB build which require some settings to be reconfigured.
c) Something else :)
Except the Error, everything else is a stab in the dark so feel free to ask for any additional info.
The problem was in the additional file needed for wsejbdeploy. In the 6.0 version, you copy wsanttasks.jar and wsprofile.jar from the websphere 6.0 installation folder and then reference it like this
<taskdef name="wsejbdeploy" classname="com.ibm.websphere.ant.tasks.WsEjbDeploy"
classpathref="all-libs"/>
where "all-libs" is a reference to the folder where you copied the jars. In websphere 7.0 there is no wsanttasks.jar and you must reference the runtime file, eg
<taskdef name="wsejbdeploy" classname="com.ibm.websphere.ant.tasks.WsEjbDeploy">
<classpath>
<pathelement path="C:/IBM/SDP80/runtimes/base_v7/plugins/com.ibm.ws.runtime.jar" />
</classpath>
My PC is currently set up as Japanese for testing purposes. If my java project has a compilation error the message is reported in Japanese.
e.g.
Compiling 1 source file to [...directory...]
[...class...].java:172: シンボルを見つけられません。
I would prefer to see the errors in english.
Without using ant the fix for this is to use
javac -J-Duser.language=en [..java files...]
which makes javac give english error messages (the -J tells javac to pass the rest of the argument to java)
My question is: how do I pass this to ant
[editted to remove options I tried that didn't work]
Try adding a <compilerarg> to your <javac> call. For example:
<javac srcdir="${src.dir}" destdir="${classes.dir}" fork="true">
<compilerarg value="-J-Duser.language=en"/>
<compilerarg value="-J-Duser.country=GB"/>
</javac>
EDIT Fixed the arg values. Also, this only works if the compiler is forked; I updated the example to reflect that.