Illegal start of expression for Annotations
I am using Ant to build, I'm getting these errors:
Buildfile: ...\build.xml
clean:
[delete] Deleting directory D:\IdanWorkSpace\ECMSEJB\classes
ejb.compile:
[mkdir] Created dir: D:\IdanWorkSpace\ECMSEJB\classes
[javac] Compiling 26 source files to D:\IdanWorkSpace\ECMSEJB\classes
[javac] ...\src\com\mirs\ecms\mdb\ECMSDispatcherMDB.java:28: illegal start of expression
[javac] })
[javac] ^
[javac] ...\src\com\mirs\ecms\mdb\ECMSErrorHandlerMDB.java:25: illegal start of expression
[javac] }
[javac] ^
[javac] 2 errors
The java class: ECMSDispatcherMDB.java
@MessageDriven( activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination",
propertyValue = Constants.CALLS_QUEUE_LOOKUP),
@ActivationConfigProperty(propertyName = "maxSession",
propertyValue = "50"),
@ActivationConfigProperty(propertyName = "transactionTimeout",
propertyValue = "30000"),
} )
public class ECMSDispatcherMDB implements MessageListener
{
Logger logger = Logger.getLogger("ecms.log");
private static final String TAG = "ECMSDispatcherMdb";
ConnectorManager connectorManager = ConnectorManager.getInstance();
@EJB
private ECMSEntityManagerDaoLocal dao;
...
The java class: ECMSErrorHandlerMDB.java
@MessageDriven( activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination",
propertyValue = Constants.ERORR_QUEUE_LOOKUP),
@ActivationConfigProperty(propertyName = "maxSession",
propertyValue = "50"),
} )
public class ECMSErrorHandlerMDB implements MessageListener
{
Logger logger = Logger.getLogger("ecms.log");
private static final String TAG = "ECMSErrorHandlerMDB";
ConnectorManager connectorManager = ConnectorManager.getInstance();
@EJB
private ECMSEntityManagerDaoLocal dao;
...
And here's the Ant buildfile build.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="ECMS Ant" basedir="." default="create ear">
<property file="build.properties" />
<path id="base.path">
<fileset dir="${project.lib}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${project.lib2}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean" description="Delete all generated files">
<delete dir="${ejb.classes.dir}" />
<delete dir="${web.classes.dir}" />
<delete dir="${deploy.dir}" />
</target>
<target name="ejb.compile" description="Compiles the Task" depends="clean">
<mkdir dir="${ejb.classes.dir}" />
<javac srcdir="${ejb.src.dir}" destdir="${ejb.classes.dir}">
<classpath>
<path refid="base.path" />
</classpath>
</javac>
</target>
<target name="web.compile" description="Compiles the Task" depends="ejb.compile">
<mkdir dir="${web.classes.dir}" />
<javac srcdir="${web.src.dir}" destdir="${web.classes.dir}">
<classpath>
<path refid="base.path" />
<path refid="${ejb.classes.dir}" />
</classpath>
</javac>
</target>
<target name="create jar" description="create jar" depends="ejb.compile">
<!-- new jars-->
<jar destfile="${deploy.dir}/ecmsejb.jar">
<fileset dir="${ejb.classes.dir}">
<!-- include the folders: facade -->
</fileset>
<metainf dir="${ejb.src.dir}/META-INF" >
<!--exclude name="*application.xml" /-->
</metainf>
</jar>
</target>
<target name="create war" description="Creates war file" depe开发者_如何学运维nds="web.compile">
<war warfile="${deploy.dir}/ecmsweb.war"
webxml="${web.project.root}/WebRoot/WEB-INF/web.xml">
<webinf dir="${web.project.root}/WebRoot/WEB-INF/" />
<classes dir="${web.classes.dir}">
<!-- include the folders: webServices -->
</classes>
<classes dir="${web.project.root}/WebRoot/WEB-INF/classes" />
</war>
<!--delete dir="${project.root}/WebRoot/WEB-INF/classes/META-INF" /-->
</target>
<target name="create ear" description="create ear" depends="create war">
<ear destfile="${deploy.dir}/ecms.ear"
appxml="${project.root}/META-INF/application.xml">
<fileset dir="${deploy.dir}" />
<metainf dir="${project.root}/META-INF" />
</ear>
</target>
</project>
The errors are related to the Annotations I am using. What do I need to do to fix this Ant build to compile my class Annotations?
It looks like you have trailing commas in your annotation arrays, which javac views as illegal - unlike in 'proper' arrays. (There is a bug in eclipse that doesn't report these as such.)
Remove the trailing commas, e.g.:
@MessageDriven(activationConfig =
{ @ActivationConfigProperty( ... ),
@ActivationConfigProperty( ... ),
@ActivationConfigProperty( ... ),
@ActivationConfigProperty( ... ) // no comma here
} );
Are you defining a different source level for javac
?
Since it is recommended to always specify the source
attribute for the javac
task, you might have some outdated version specified there.
If your Ant script for example compiles using source level 1.4, you won't have generics or annotations.
Look for something like this in your build.xml
:
<javac ... source="1.x" ... />
EDIT: One other way to set the source level for Ant would be using the system property ant.build.javac.source
, but I doubt that's the case here.
This is not an Ant problem per se. Rather, it is most likely a syntax error in one or more of the Java files that you are trying to compile.
If you posted the Java source code, we should be able to be more specific.
I don't know what the problem is, but I can tell you for a fact that Ant does not compile Java itself. Instead, it uses the Java compiler (from the JDK that it finds) to compile the Java.
So if you are getting compilation errors when you compile via Ant, but not when you compile some other way then there is something significant that is different about the way that the Java compiler is being run:
- You might be using a different compiler (from a different JDK).
- You might be causing the compiler to be run with a different build classpath.
- You might be causing the compiler to be run with a different source level.
The second datapoint is the actual errors you are getting. They are syntax errors rather than semantic errors. If the problem was the build classpath, then you'd expect semantic errors saying (for instance) that certain annotation names were not known. Instead, you are getting an syntax error that suggests that the compiler doesn't understands annotations at all. That suggests that the problem is that the compiler is expecting Java 1.4 (or earlier) code.
So my suggestions are:
- Check that Ant is configured to use a recent JDK. Check your Ant installation and environment variables as described in the Ant documentation.
- Check that you've correctly set the compiler source level in the Ant build.xml file. Read the Ant documentation for the
<javac>
task, and look at the Sun javac manual entry to make sure that you doing it right.
This strongly points towards Java compilation level, @DR already answered it. Try two things:
- Download latest ANT, add
$ANT_HOME/bin
it to System Path, where$ANT_HOME
is the directory where ANT resides (under which bin exists). Remove any reference to any other ANT. Open your build.xml, look the the block where
javac
(compilation) task is added. Make sure it looks like this<target name="ejb.compile" description="Compiles the Task" depends="clean"> <mkdir dir="${ejb.classes.dir}" /> <javac srcdir="${ejb.src.dir}" destdir="${ejb.classes.dir}" fork="true" source="1.6" target="1.6"> <classpath> <path refid="base.path" /> </classpath> </javac> </target> <target name="web.compile" description="Compiles the Task" depends="ejb.compile"> <mkdir dir="${web.classes.dir}" /> <javac srcdir="${web.src.dir}" destdir="${web.classes.dir}" fork="true" source="1.6" target="1.6"> <classpath> <path refid="base.path" /> <path refid="${ejb.classes.dir}" /> </classpath> </javac> </target>
精彩评论