Javadoc linking to other API - java

I am generating Javadoc for my project and I want to link to the APIs of other projects that we use. I am doing the following: (I have tried with and without the packagelistURL and various versions of the API even though we are using 3.1)
<target name="javadoc" depends="initLocal">
<echo>Generating javadoc</echo>
<javadoc packagenames="*" sourcepath="${srcdir}" destdir="${docdir}" access="public" verbose="false">
<link offline="false" href="http://docs.oracle.com/javase/6/docs/api/" />
<link offline="false" href="http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/" packagelistURL="http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/package-list"/>
</javadoc>
</target>
I can see that it is successfully linking to the Java SE6 API but I can't seem to get it to use the commons-lang API. When I run the build I see the following:
[javadoc] C:\path\to\my\project\myClass.java:6: package org.apache.commons.lang3.builder does not exist
[javadoc] import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
[javadoc] ^
[javadoc] C:\path\to\my\project\myClass.java:7: package org.apache.commons.lang3.builder does not exist
[javadoc] import org.apache.commons.lang3.builder.ToStringStyle;
Which seems a bit odd as the API link works and I can see both of those classes in the API. The project compiles correctly and the commons-lang jar is on the build path of the project.
Any ideas on what I am doing wrong here?

You've specified a link, but you haven't specified a classpath - you need to tell the javadoc task where to find the jar files (or whatever) which contain those types, just as you do when building. You should almost certainly use the same classpath for javadoc as you do for your javac task.

Related

Java and ProGuard - taskdef class proguard.ant.ProGuardTask cannot be found using the classloader AntClassLoader

I have the pleasure of working on a embeded java program, which was writen 10+ years ago from a third party company. Source and project files were included.
It was imported into Eclipse and ported to a higher java version (17).
Now I'm stuck when trying to build the program. It uses ProGuard. The newest version was added to the project files. Config file proguard.pro was changed to discard rt.jar utilization in favore of the new methods. However, now I'm getting a error message:
BUILD FAILED
C:\mypath\build.xml:16: taskdef class proguard.ant.ProGuardTask cannot be found
using the classloader AntClassLoader[C:\mypath\obf\proguard.jar]
build.xml (original) is as follows:
<target name="obfuscate" description="obfuscate a jar file" depends="jar">
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="obf/proguard.jar" />
<proguard configuration="obf/proguard.pro" />
</target>
The 'obf' folder is inside the project (sublevel of build.xml). File proguard.jar is inside of it. Anyone haveing any clues why would this error show? No other changes were made beside the listed ones.
So, it turned out that with new versions, the notation is not as it once was.
<taskdef resource="proguard/ant/task.properties" classpath="${proguard.path}/lib/proguard-ant.jar" />

Ignore minor errors using javadoc

I'm trying to generate the documentation, using javadoc, from one or two downloaded jar files (with the source of course, after having extracted everything).
But using javadoc, even in an Ant file, I'm being prevented from generating this because of silly things, specifically "package XXX does not exist" and "cannot find symbol"... I just want javadoc to put the text of these things (external references) in the html docs, but to document all the .java files it finds...
NB for anyone interested this is the download page with the download files (containing source) from which I'm trying to generate the API documentation: http://logback.qos.ch/download.html
Following Mark Rotteveel's help, my Ant build file now looks like this:
<?xml version="1.0" ?>
<project name="document logback core" default="doc">
<target name="doc">
<mkdir dir="javadoc" />
<property name="excludedPackages"
value="org.codehaus.*,javax.mail.*"/>
<javadoc destdir="javadoc" sourcepath="src" packagenames="main.*"
excludepackagenames="${excludedPackages}"
additionalparam="-Xdoclint:none" />
</target>
</project>
... but it still gives errors 1) about packages not being found, including "org.codehaus.[xxx...]" and "javax.mail.[xxx...]" and 2) about symbols not being found (although this may go away if I can solve the missing packages errors).
NB the build is said to be successful, but I get complaints about no source files being found (where there are indeed commented .java files), and no html at all is generated under \javadoc.
later, following Tony Pierce's success in generating these docs
Installed Ant 1.9.6, changed path accordingly, checked to make sure this was the version being used... tried again. Failed again. This was the end of my output:
[javadoc]
D:\Desktop\Downloads\logback-1.1.7.tar\logback-1.1.7\logback-core\src\test\java\ch\qos\logback\core\appender\ConsoleAppenderTest.java:32:
error: package org.junit does not exist [javadoc] import static
org.junit.Assert.assertEquals; [javadoc]_______________________^
[javadoc] javadoc: error - No public or protected classes found to
document. [javadoc] 1 error [javadoc] 100 warnings
BUILD SUCCESSFUL Total time: 2 seconds
It does create the javadoc folder... but this is empty.
NB about the above "package does not exist" error (there were many others): this one is particularly mystifying as I thought Ant somehow included junit by default (NB I am a complete newbie at Ant, just working through "Ant in Action").
But... with the Ant javac task you can set includeAntRuntime="true" ... according to this book that makes Ant's own junit.jar be included. Unfortunately the javadoc task doesn't support this attribute.
later still
My thinking was a bit muddled on this, to be honest: the simplest way I have found to compile javadocs from third-party source jars is just by extracting and then using the command line, typically:
javadoc -d docs -Xmaxwarns 10 -Xmaxerrs 10 -Xdoclint:none -sourcepath
. -subpackages ch.qos.logback.core
... as for javadoc for one's own code this doesn't seem to be a problem in Gradle (I was only glimpsing at Ant, aware that the future is Gradle... and it's not particularly difficult to get to grips with the basics).
NB If you install the Gradle STS plugin for Eclipse, and then create a new project using Gradle STS wizard your build file contains the line
apply plugin: 'eclipse'
... one of the effects of which is that by default the source as well as the executables for all your third-party dependencies will be downloaded under GRADLE_HOME during the build. Pretty good!
Java 8 introduced doclint which will treat certain problems as an error and not produce the documentation. It is possible to disable this by specifying the commandline option -Xdoclint:none.
See also: Turning off doclint in JDK 8 Javadoc
Eg in Ant you would need to do add a additionalparam="-Xdoclint:none" attribute to the javadoc task. A (slightly modified) example from Jaybird:
<target name="javadocs" depends="init,set-driver-sources">
<mkdir dir="${build.docs}"/>
<javadoc destdir="${build.docs}"
author="true"
version="true"
windowtitle="${Name} API"
doctitle="${Name}"
extdirs="${module.thirdparty}"
additionalparam="-Xdoclint:none"
excludepackagenames="${excludedPackages}"
bottom="Copyright © 2001-2015 Jaybird (Firebird JDBC/JCA) team. All rights reserved.">
<arg line="${java.module.arg}"/>
<classpath refid="javac.driver.classpath"/>
<sourcepath>
<pathelement path="${source.java}"/>
<pathelement path="${source.jna-client}"/>
</sourcepath>
<sourcepath refid="source.java.openoffice"/>
<sourcepath refid="source.java.additional"/>
<link href="http://docs.oracle.com/javase/7/docs/api/"/>
</javadoc>
</target>
Compile Errors With Custom Doclet with Java 9 or later
The -Xdoclint:none is an option of the standard doclet which will not work for custom doclets.
If you have a custom doclet and don't care about compilation errors, you can pass the --ignore-source-errors option either to the javadoc command line tool or to javax.tools.DocumentationTool.getTask(...) if you invoke your doclet programmatically.
The --ignore-source-errors option is not documented. Maybe because it might be removed in future. The clean way is to add all required libraries to the classpath (via the -classpath option to actually resolve the compilation errors).
I simplified your build file a bit and built the javadoc successfully. Here's what I did:
Downloaded the logback zip
Expanded the sources jars inside into a src directory
Ran ant 1.9.6 under java 8 with this:
<?xml version="1.0" ?>
<project name="document logback core" default="doc">
<target name="doc">
<mkdir dir="javadoc" />
<javadoc destdir="javadoc" sourcepath="src"
additionalparam="-Xdoclint:none" />
</target>
</project>
It produced a lot of warnings, but created a javadoc directory filled with html.
I removed excludepackagenames and dropped the packagenames element. In any case, packagenames="main.*" prevents the javadoc generation because the only root packages in the jar are ch and org.

rt.jar com.sun.istack.internal packages

jre comes with many libraries in rt.jar one of which is com.sun.istack.internal*. I needed the documentation of com.sun.istack.internal.Nullable(which I found being used by google in its CacheBuilder) and first I thought was to go to docs.oracle.com to find its documentation and there I found nothing about it. Next went to source folder sourced with jdk and I didn't find com name entity in the said folder. Next I take a look at the jre7 release and take a look at all the packages and class and found no mention of Nullable there. Though SO had one mention of it, but nothing concrete. I am still puzzled where to get its documentaion and src if needed. I even looked legacy sun api documentation at oracle but nothing mentioned about it. where does oracle document there policy about ported packages and their being standard or not-standard.They must have documented it somewhere it is just that I'm taking too much of time to get there.
Please point me there.
EDIT: Actually the javax.annotation.Nullable is being used in google CacheBuilder and not com.sun.istack.internal.Nullable.
Also for someone who may face this issue: javax.annotation.Nullable is not part of Java SE as of now, and it is being ported in jsr305 jar. So if you are planning to use CacheBuilder or just going through its code, do add jsr305 jar in your class path, else eclipse get confuse and will point you to com.sun.istack.intenal.Nullable when ever you hover your cursor over Nullable.
Guava doesn't use com.sun.istack.internal.Nullable. Everything that is not documented in the official Java SE javadoc is internal code, and should not be used in applications.
You're probably looking for javax.annotation.Nullable, which is part of JSR305.
Here is a link to the source code:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/com/sun/istack/internal/Nullable.java/
(This link may break in the future, but you should be able to find an equivalent using a Google search.)
The reason that you can't find the source code or javadocs in the standard JDK / JRE distributions is that this is a INTERNAL class. There is a long-standing Oracle / Sun policy of discouraging developers from writing code that is dependent on Java internal classes.
FWIW - this is just an annotation, and the meaning is pretty much what the class name implies.
UPDATE - Apparently, the real cause of this confusion is that you didn't include the JSR305 jar in your buildpath. It is a dependency for CacheBuilder. Eclipse classname completion is then doing its best ... but failing.
It is said that It's Oracle's intent that these classes be inaccessible at compile-time.
Below is my workaround in case adding a modern jar for those annotation is not allowed.
If using Gradle, add:
compileJava.options.compilerArgs << "-XDignore.symbol.file"
If using Ant, change the javac tag like:
<javac srcdir="src" destdir="${classes.dir}" classpathref="classpath" memoryinitialsize="512m" memorymaximumsize="1024m" fork="true">
<compilerarg line="-encoding utf-8 -XDignore.symbol.file"/>
<exclude name="test/**"/>
</javac>

Android.App.Activity - package does not exist

I got an andorid project files that are supposed to compile correctly.
I installed the latest eclipse and Andriod ADT plugins.
I then imported the project and right clicked build.xml to run as ANT build. but I got erors on some basic code which I am sure is originating from my misconfigured setup.
I also tried to run it using ANT from the command line. both times I got the same type of errors
What is wrong ?
Buildfile: /Users/admin/Downloads/moshe-5/build.xml
init:
process.annotations:
[javac] Compiling 9 source files to /Users/admin/Downloads/moshe-5/build/classes
[javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:7: package android.app does not exist
[javac] import android.app.Activity;
[javac] ^
[javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:8: package android.content does not exist
[javac] import android.content.Context;
[javac] ^
[javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:9: package android.graphics does not exist
[javac] import android.graphics.Color;
In my case, it was due to the problem that I didn't have a default.properties file with the target field in it.
I had to manually create the file and put
target=android-9
Or other Android target version.
If you run
ant -v
with your build command, you'll probably see this line
Property "target" has not been set
and
[property] Unable to find property file: /PATH_TO/default.properties
Those messages are enough hints.
Hope this solves your problem too.
It is not finding the android packages. IN the build step you should include android.jar corresponding to the android version you want to port to.
When you write your compile target, you are overriding the default one given by android_rules.xml located in: C:\Program Files (x86)\Android\android-sdk\platforms\android-8\templates or wherever android_rules.xml is located on your computer.
Like Potter mentioned above it is not finding the android library and other libraries, so please look at android_rules.xml to see how it sets up the proper libraries:
<target name="compile" depends="-resource-src, -aidl"
description="Compiles project's .java files into .class files">
<!-- If android rules are used for a test project, its classpath should include
tested project's location -->
<condition property="extensible.classpath"
value="${tested.project.absolute.dir}/bin/classes" else=".">
<isset property="tested.project.absolute.dir" />
</condition>
<condition property="extensible.libs.classpath"
value="${tested.project.absolute.dir}/libs" else="./libs">
<isset property="tested.project.absolute.dir" />
</condition>
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
destdir="${out.classes.absolute.dir}"
bootclasspathref="android.target.classpath"
verbose="${verbose}" classpath="${extensible.classpath}">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<classpath>
<fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
</classpath>
</javac>
</target>
Inside the classpath tags is where android.jar is included. You can add other libraries by adding more filesets
Some other good examples of code for writing the ANT compile target are:
Can't build and run an android test project created using "ant create test-project" when tested project has jars in libs directory <-- this worked for me
http://www.vogella.de/articles/ApacheAnt/article.html
http://www.alittlemadness.com/2010/05/31/setting-up-an-android-project-build/ <-- setting up ANT project
It's most likely not finding Android because you didn't define the sdk.dir property, which tells the build process where to find Android. This property is usually in a local.properties file and is populated when you do:
android update project
as described here:
http://developer.android.com/tools/projects/projects-cmdline.html#UpdatingAProject
Don't bother building using ANT.
Eclipse and the ADT plugin provide excellent tool to save you the trouble.
Simply right click the project, choose run as -> Android application

Javadoc on Android (Eclipse)

I am trying to generate Javadoc html pages for my Android project in Eclipse. I have tried using the -linkoffline argument, as suggested here, as well as using the -classpath argument pointing to my android.jar file. Neither of these worked, as I still get package android.app does not exist (and other) warnings. I have also tried running the javadoc tool from the command line, rather than using Eclipse.
Ideally I would like to have my own generated pages for my classes, with all android.* and java.* classes linking to the online pages. I am using Mac OS 10.6 with Java version 1.6.0_20.
While trying to resolve a similar issue myself, the two main points I've found have been:
To include the android.jar file you're linking to within the classpath attribute of the javadoc Ant task. That means something like the following:
<javadoc ...
classpath="some/local/library.jar;
C:/Android/platforms/android-8/android.jar;
D:/another/library.jar" ... >
To add a link subitem under javadoc task in order to match the online Android Reference URL with a local copy of Android Reference package-list. That means something like the following:
<javadoc ...>
<link offline="true"
href="http://developer.android.com/reference/"
packagelistloc="C:/Android/docs/reference" />
</javadoc>
This was enough for me in order to show Android links within my project Javadoc.
Have you tried using an ant script for the javadocs? Name it javadoc.xml or something other than build.xml - else eclipse will pick it up as the default build script. Run the ant script either from inside eclipse (RMB on file | Run As | Ant Build), or from the console: ant -f <file-name.xml>.
Mine looks something similar to this:
<project basedir="." default="doc" name="metagloss api docs">
<property
name="android-sdk-docs"
value="/home/blackrax/opt/dev/android-sdk-linux_86/docs/reference"/>
<target name="doc" description="api docs - no piwik" depends="clean, delombok">
<javadoc destdir="docs">
<link offline="true"
href="http://d.android.com/reference"
packagelistLoc="${android-sdk-docs}" />
<fileset dir="src" includes="**/*.java" />
</javadoc>
</target>
<!-- more implementation, any remaining targets -->
</project>

Categories