error compiling package-info.java

F

frank

I'm using JAXB/xjc to generate code to access my schema. It created a
package-info.java file along with other files. Everything compiles fine
except for the package-info.java file it gives me an error of "package
annotations should be in file package-info.java at line 8 (8:1)"

file looks like this:
@javax.xml.bind.annotation.XmlSchema(namespace =
"urn:us:gov:dod:army:cerdec:jbfsa:csds:r1", elementFormDefault =
javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package csds.message;

it is in a file called packag-info.java, why will it not compile?

Thanks,

Frank
 
A

Andrew Thompson

frank said:
I'm using JAXB/xjc to generate code to access my schema. It created a
package-info.java file along with other files. Everything compiles fine
except for the package-info.java ....
it is in a file called packag-info.java, why will it not compile?

1) So is it ..
'package-info'
...or ..
'packag-info'
?

2) Common nomencature for Java *classes* is
EachWordUpperCase, so that should be PackageInfo.java

And as an aside, why do you include characters like
'-' in source/class names? It seems an 'open invitation to
a mess of trouble'.

Is this class contained in a package?

Andrew T.
 
D

Daniel Dyer

1) So is it ..
'package-info'
..or ..
'packag-info'
?

2) Common nomencature for Java *classes* is
EachWordUpperCase, so that should be PackageInfo.java

And as an aside, why do you include characters like
'-' in source/class names? It seems an 'open invitation to
a mess of trouble'.

Is this class contained in a package?

Andrew T.

The name is correct, it's the new preferred way of providing package
summaries for Javadoc (and for applying annotations to packages).

Unfortunately javac doesn't like it and you have to exclude it from the
source set.

Dan.
 
D

Daniel Dyer

The name is correct, it's the new preferred way of providing package
summaries for Javadoc (and for applying annotations to packages).

Unfortunately javac doesn't like it and you have to exclude it from the
source set.

Sorry, that post wasn't as helpful as it could have been - I didn't read
Frank's post that Andrew was responding to, and as such didn't notice that
he was using annotations.

It's more correct to say that package-info.java was introduced to provide
a way for annotations to be applied to packages. A side benefit was that
it provided a more logical place for javadoc comments for packages than
package.html. So far I've not needed to use it for annotations, just for
Javadoc, so when I had problems I added an exclude pattern to the compile
task in my Ant build files. However, giving it some thought I couldn't
remember exactly what led me down this path and it didn't make much sense
that the compile should fail. So I've just removed the exclusion from one
of my projects and there is no complaint from the compiler (1.5.0_06 on a
Mac). So, either it is only a problem with certain earlier versions (this
was a while ago with 1.5.0_something on Windows) or I had some other
reason, that I don't recall, for wanting to exclude it.

However, if the package *is* annotated, as in the OP's example, the
package-info.java *should* be compiled and the compiler should output a
synthetic package-info.class (if it didn't output anything the package
level annotations would be lost). So, returning to Frank's problem... I
have no idea why it doesn't work :)

Dan.
 
Joined
May 18, 2009
Messages
1
Reaction score
0
Plz try this
it resolved the problem for me

IOW JAX-WS client have been working only the first time I compile them. I couldn’t figure out why it have been working in that manner, but after a lot of google search I got this commit. In practice what have been happening is better described in “Note on package-info.java” paragraph of javac target in ant manual. Starting from version 1.7.1 ant compile package-info.java only in these 3 case:

If a package-info.class file exists and is older than the package-info.java file.
If the directory for the package-info.class file does not exist.
If the directory for the package-info.class file exists, and has an older modification time than the the package-info.java file. In this case <javac> will touch the corresponding .class directory on successful compilation.
In practice if you havea ant task like mine:

<target name=”compile” depends=”init” description=”Compile the Java source code”>
<touch>
<fileset dir=”${src.java.dir}” includes=”**/package-info.java”/>
</touch>
<javac destdir=”${classes.dir}” classpathref=”build.classpath” debug=”${javac.debug}” deprecation=”${javac.deprecation}” target=”1.5″>
<src path=”${src.java.dir}” />
</javac>

Here the compilation target compile all files and so create directory where package-info.class will be contained during other generated files compilation. In this case the compilation target never re-generate package-info.class because no one of the 3 conditions is true. My workaround have been to change my build.xml file and have this compile target:

<target name=”compile” depends=”init” description=”Compile the Java source code”>
<touch>
<fileset dir=”${src.java.dir}” includes=”**/package-info.java”/>
</touch>
<javac destdir=”${classes.dir}” classpathref=”build.classpath” debug=”${javac.debug}” deprecation=”${javac.deprecation}” target=”1.5″>
<src path=”${src.java.dir}” />
</javac>
 

ips

Joined
Sep 22, 2009
Messages
1
Reaction score
0
I was seeing this error in a Maven build. It ended up being due to JDK5 javac being in my PATH. Even though JAVA_HOME was pointing to JDK6, this particular part of the Maven build (which was attempting to compile JAXB-XJC-generated Java source files) was calling javac from the PATH, rather than $JAVA_HOME/bin/javac. Removing the JDK5 javac and java from my PATH solved the issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top