I want to run a Netbeans 7.3 platform application (let's name it app A) from another Java application (app B). To do this, in B's code I'm invoking the Ant library as follows:
Path pathA = ... // where the A's sources are
Path fileBuild = pathA.resolve("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", fileBuild.toFile().getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.setDefault("run");
p.executeTarget(p.getDefaultTarget());
Unfortunately, the error I'm getting is:
C:\Program Files\NetBeans 7.3\harness\suite.xml:184: The following error occurred while executing this line:
C:\Program Files\NetBeans 7.3\harness\common.xml:217: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files (x86)\Java\jdk1.7.0_45\jre"
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:568)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:443)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:221)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
...
The JAVA_HOME variable is set correctly both as system path variable and in netbeans config file and points to C:\Program Files (x86)\Java\jdk1.7.0_45.
The question is, what am I missing? When running the app A from Netbeans menu, everything runs fine, so what should I append to the build file/ant settings to achieve A runs from B's code execution?
Thanks in advance!
Edit: I managed to get a more precise error stack, maybe this can help.
Error on test cases execution.
C:\Program Files\NetBeans 7.3\harness\common.xml:217: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files (x86)\Java\jdk1.7.0_45\jre"
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:130)
at org.apache.tools.ant.taskdefs.Javac.findSupportedFileExtensions(Javac.java:984)
at org.apache.tools.ant.taskdefs.Javac.scanDir(Javac.java:961)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:932)
at org.netbeans.nbbuild.CustomJavac.execute(CustomJavac.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at odoetest.server.ServerInvokerAnt.start(ServerInvokerAnt.java:48)
at odoetest.EntryPoint.invokeTests(EntryPoint.java:58)
at odoetest.EntryPoint.main(EntryPoint.java:38)
Edit-2: I don't have any separate ant installation and use the ant delivered with Netbeans. When I run ant -diagnostics, I get this info. When I invoke the build or run job from the command line like
ant -f /path/to/build.xml run
no errors are thrown, the program starts. I just can't do the exact same thing from java code from above.
Your Ant build.xml will still be referring to a JRE rather than the JDK.
Right-click on your project, select Libraries, check that Java Platform points to a JDK rather than a JRE. See here for details.
If this fails:
You can explicitly set properties for Project p
as in manouti's answer above. This will ensure that Project p as well as Project A will be referring to a JDK rather than JRE. AFAIK, no need to fork.
You can set properties in your .properties file, though it is not always easy to debug whether this is being implemented for each project.
You can explicitly include folders/files on the classpath of your target using the <classpath> element - see the Apache Ant Manual for some not very clear documentation.
This would be:
<classpath>
<pathelement path="${path.to.jdk}"/>
</classpath>
See also this answer.
NetBeans has setting which java to use internally. It's part of the netbeans.conf file. You are able to set the Java version for every NetBeans project which might be different.
However your JAVA_HOME points to a JRE and not JDK. That's why it cannot find the compiler - javac.
The error is occurring when calling the Ant javac task. Try to locate the call to that task (it should be in common.xml at the line shown in the error message), and try adding fork="yes" to it so that it runs the JDK compiler in an external process. See http://ant.apache.org/manual/Tasks/javac.html:
<javac fork="yes" ...
Also try adding the following property in the project invocation:
Project p = new Project();
p.setUserProperty("ant.file", fileBuild.toFile().getAbsolutePath());
p.setProperty("java.home", "C:\\Program Files (x86)\\Java\\jdk1.7.0_45");
Related
I'm running java tests with gradle.
here is the exception I have:
java.lang.RuntimeException: java.lang.IllegalStateException: Unable to load Java agent; please add lib/tools.jar from your JDK to the classpath
at org.powermock.modules.agent.PowerMockClassRedefiner.redefine(PowerMockClassRedefiner.java:59)
at org.powermock.modules.agent.support.PowerMockAgentTestInitializer.redefine(PowerMockAgentTestInitializer.java:49)
at org.powermock.modules.agent.support.PowerMockAgentTestInitializer.initialize(PowerMockAgentTestInitializer.java:41)
at com.blablacompany.app.weight.WeightMilestonesViewBeanUnitTest.setUpMock(WeightMilestonesViewBeanUnitTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unable to load Java agent; please add lib/tools.jar from your JDK to the classpath
at org.powermock.modules.agent.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:97)
at org.powermock.modules.agent.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:70)
at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:40)
at org.powermock.modules.agent.PowerMockAgent.verifyInitialization(PowerMockAgent.java:83)
at org.powermock.modules.agent.PowerMockAgent.instrumentation(PowerMockAgent.java:76)
at org.powermock.modules.agent.PowerMockClassRedefiner.redefine(PowerMockClassRedefiner.java:57)
... 37 more
It turns out that for some reason my gradle uses JRE's folder as java.home and this is why it can not find the tools.jar.
I on't think that I want manually add it to my classpath though. I'm wondering if there any way to tell gradle to use JDK's java home instead of JRE's?
I also tried overriding it using org.gradle.java.home in gradle.properties file and it did not work. Any help is greatly appreciated.
WHen I run the same tests from my IDE(Intellij IDEA) all tests are passed successfully. I'm running all it on Mac OS.
println System.getenv("JAVA_HOME")
println System.properties['java.home']
displays:
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre
It's not a JDK vs. JRE problem. The values of JAVA_HOME vs. java.home are correct and expected (see other SO question on this topic). tools.jar is necessary to execute tools such as javac and javadoc. However, neither the JDK's javac command line compiler nor Gradle's JavaCompile task will automatically put tools.jar on the compile class path of user code. Instead you'll have to add it explicitly. For example:
def jdkHome = System.getenv("JAVA_HOME")
dependencies {
compile files("$jdkHome/lib/tools.jar")
}
Ok, seems that JRE is actually the right one that I need to use. No reason java.home to be set to JDK.
So the way I solved it was just adding tools library to my classpath:
testCompile ([fileTree(dir: "${System.properties['java.home']}/../lib", include: '*tools.jar'),fileTree(dir: "lib/test", include: '*.jar') ])
Initially the reason why I did not wanted to do this was that once I added it I had a bunch of
java 7 errors: java.lang.VerifyError: Expecting a stackmap frame at branch target 10
I did fix it by adding "-noverify" parameter to my tests closure:
Closure basicTestConfiguration = {
jvmArgs "-Dactivemq.directory=${testActivemqDir}",
"-Duser.timezone=Etc/UTC",
"-javaagent:${configurations.testAgent.singleFile}",
"-XX:MaxPermSize=256m",
"-noverify"
...
}
and applying this closure to my test suite:
postCommitSuite basicTestConfiguration
Edited
Check this out http://www.gradle.org/docs/current/userguide/build_environment.html.
Especially this section
The configuration is applied in following order (in case an option is configured in multiple locations the last one wins):
from gradle.properties located in project build dir.
from gradle.properties located in gradle user home.
from system properties, e.g. when -Dsome.property is used in the command line.
I have both JAVA_HOME and ANT_HOME set:
damechen#ubuntu:~/apache-tomcat-7.0.42-src$ echo $ANT_HOME
/home/damechen/tmp/damechen/apache-ant-1.9.1
damechen#ubuntu:~/apache-tomcat-7.0.42-src$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.7.0.25
damechen#ubuntu:~/apache-tomcat-7.0.42-src$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
I was trying to use ant to build tomcat, but it failed for some reasons related to build.xml.
BUILD FAILED
/home/damechen/apache-tomcat-7.0.42-src/build.xml:2396: The following error occurred while executing this line:
/home/damechen/apache-tomcat-7.0.42-src/build.xml:2625: Directory /usr/share/java/tomcat-native-1.1.27 creation was not successful for an unknown reason
at org.apache.tools.ant.taskdefs.Mkdir.execute(Mkdir.java:70)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440)
at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
damechen#ubuntu:~/apache-tomcat-7.0.42-src$
Anyone can kindly give me a hand? Thanks a lot!
As the exceptions says. The built failed while it was trying to create a directory by the name tomcat-native-1.1.27 in /usr/share/java/.
Please give proper rights.
You need to read the build instructions for Apache tomcat:
http://svn.apache.org/repos/asf/tomcat/tc7.0.x/tags/TOMCAT_7_0_42/BUILDING.txt
(3.2) Building
The build is controlled by creating a ${tomcat.source}/build.properties
file.
It is recommended to always create the file, because of unfortunate
default value of base.path property. You may start with the following
content for the file:
# ----- Default Base Path for Dependent Packages -----
# Replace this path with the directory path where dependencies binaries
# should be downloaded
base.path=/home/me/some-place-to-download-to
Configure base.path property by adding it to the
${tomcat.source}/build.properties file.
The base.path property specifies the place where Tomcat dependencies
required by the build are downloaded. It is recommended to place this
directory outside of the source tree, so that you do not waste your
time re-downloading the libraries.
WARNING: The default value of base.path property makes the build script
to download libraries required to build Tomcat to the /usr/share/java
directory. On a typical Linux or MacOX system an ordinary user will not
have access to write to this directory. Even if you do have access to
that directory, it is likely not appropriate for you to write there.
Note the warning at the end.... This is the root cause of your issue.
Analysis
The build file is calling the "download-2" target when it fails:
<target name="extras-commons-logging-prepare"
depends="extras-prepare"
description="Prepare to build web services extras package">
<antcall target="downloadfile-2">
<param name="sourcefile.1" value="${commons-logging-src.loc.1}"/>
<param name="sourcefile.2" value="${commons-logging-src.loc.2}"/>
<param name="destfile" value="${commons-logging-src.tar.gz}"/>
<param name="destdir" value="${commons-logging.home}"/>
</antcall>
..
..
In your build.properties file you have set the value of the commons-logging.home property to a directory path for which you do not have permissions to create a directory namely:
/usr/share/java/...
Digging further I see that default properties file sets this path as follows:
# ----- Default Base Path for Dependent Packages -----
# Please note this path must be absolute, not relative,
# as it is referenced with different working directory
# contexts by the various build scripts.
base.path=/usr/share/java
#base.path=C:/path/to/the/repository
#base.path=/usr/local
..
..
commons-logging.version=1.1.1
commons-logging.home=${base.path}/commons-logging-${commons-logging.version}
This might be a doclet-implementation-specific question, but I believe its really a JavaDoc configuration issue I'm dealing with here.
I'm trying to get the yDoc UML Doclet to work so that it will generate UML diagrams for my Java app as part of the Ant build. I downloaded the project (community edition) and have tried adapting their build-sample.xml but can't quite get it to work.
Here's my project directory structure:
MyProject/
src/main/java/
<All the Java sources I want documented and diagrammed>
bin/main
<Compiled binaries of src/main/java/>
lib/
styleed.jar
ydoc.jar
resources/
<All the yDoc resources that came with the download>
umldoclet/
<Where I want all JavaDocs to go>
build.xml
Here's build.xml:
<project name="MyProject" default="ydoc" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<!-- The "compile" task and all its dependencies omitted for brevity,
but they all absolutely work 100% and "compile" places compiled
CLASS files under bin/main. -->
<target name="ydoc" depends="compile">
<property name="ydoc.home" value="${basedir}"/>
<javadoc source="1.5" destdir="./umldoclet" additionalparam="-breakiterator">
<packageset dir="src/main">
<include name="java/**"/>
</packageset>
<doclet name="ydoc.doclets.YStandard" path="${ydoc.home}/lib/ydoc.jar;${ydoc.home}/resources">
<param name="-author"/>
<param name="-generic"/>
<param name="-umlautogen"/>
<param name="-filterpath" value="./lib/ydoc.jar"/>
<param name="-filter" value="ydoc.filters.ExcludeFilter"/>
<param name="-tag" value="y.precondition"/>
<param name="-tag" value="y.postcondition"/>
<param name="-tag" value="y.complexity"/>
<param name="-tag" value="param"/>
<param name="-tag" value="return"/>
<param name="-tag" value="see"/>
<param name="-tag" value="y.uml"/>
</doclet>
</javadoc>
</target>
</project>
When I run the ydoc task, even running Ant in "verbose" mode with the -v argument, I see the [ydoc] task getting called in the Ant Console, followed by a log statement that reads "Generating Javadoc" and about 20 lines from the verbose output regurgitating the yDoc params back to me, then a final log message saying "Javadoc execution". Then, the following stunningly-vague IOException:
BUILD FAILED
<my-eclipse-home>/MyProject/build.xml:200: Javadoc failed: java.io.IOException: Cannot run program "javadoc": java.io.IOException: error=2, No such file or directory
at org.apache.tools.ant.taskdefs.Javadoc.execute(Javadoc.java:1765)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Caused by: java.io.IOException: Cannot run program "javadoc": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
at java.lang.Runtime.exec(Runtime.java:610)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495)
at org.apache.tools.ant.taskdefs.Javadoc.execute(Javadoc.java:1759)
... 15 more
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
at java.lang.ProcessImpl.start(ProcessImpl.java:81)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)
... 20 more
Is there any way to get more details out of Ant? To find out what file or directory its referring to in the exception? Any JavaDoc/yDoc gurus ever ran into this before? Is my project directory structure set up incorrectly, or different than what the Ant build is looking for? I believe I have my doclet/path attribute set up correctly, and using the correct path separators (I'm on Ubuntu Linux). For the life of me I can't figure out where to go from here, or how to go about diagnosing the underlying issue here! Thanks in advance!
Edit/Update:
Thanks to everyone so far for the suggestions. I am doing away with Eclipse totally (as far as the build is concerned and just running Ant from the command-line; this is fine for now. When I do this, I get a successful build (so Eclipse was at least partly the culprit), however still no yDoc generation.
Now, when I run Ant from the terminal with the verbos (-v) option, here's what I see:
Hundreds of warnings that look the same, but with different classes:
[javadoc] Constructing Javadoc information...
[javadoc] /<path-to-my-project>/MyProject/src/main/java/com/some/pkg/SomeObject.java:11: package org.springframework.beans.factory.annotation does not exist
[javadoc] import org.springframework.beans.factory.annotation.Autowired;
[javadoc] ^
After hundreds of those, I get the following output (1 of these for every package in my source tree):
[javadoc] javadoc: warning - No source files for package java.com.some.pkg.<whatever>
Last, the final section of the verbose build output:
[javadoc] Valid license file found.
[javadoc] Registered Filter ydoc.filters.ExcludeFilter ...
[javadoc] Registered Taglet for tag #y.complexity ...
[javadoc] Registered Taglet for tag #y.precondition ...
[javadoc] Registered Taglet for tag #y.postcondition ...
[javadoc] Registered Taglet for tag #y.author ...
[javadoc] 1 error
[javadoc] 109 warnings
[javadoc] javadoc: error - No public or protected classes found to document.
BUILD SUCCESSFUL
Total time: 6 seconds
Furthermore, if it were executing correctly, it should be places all the JavaDocs under the uml-doclet/ directory in my project root. It does no such thing!
So it looks like there are several more things going on:
The JavaDoc can't see my 3rd party dependencies (such as Spring, Camel, etc.); hence the list of hundreds of warnings
It can't find any of my sources to document
Again, the bounty goes to anyone who can help me get this working. Thanks again for all the help so far!
If you execute ant with -verbose -debug you will either see these lines:
Setting project property: ydoc.home -> /var/tmp/ydoc-test
[javadoc] scanning /var/tmp/ydoc-test/src/main for packages.
dirset: Setup scanner in dir /var/tmp/ydoc-test/src/main with patternSet{ includes: [java/**] excludes: [] }
[javadoc] Generating Javadoc
[javadoc] Executing '/usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc' with arguments:
[...]
Or you will see these lines:
Setting project property: ydoc.home -> /var/tmp/ydoc-test
[javadoc] scanning /var/tmp/ydoc-test/src/main for packages.
dirset: Setup scanner in dir /var/tmp/ydoc-test/src/main with patternSet{ includes: [java/**] excludes: [] }
[javadoc] Generating Javadoc
[javadoc] Executing 'javadoc' with arguments:
In the first case Eclipse/Ant have found a valid javadoc command and tell you so in the line [javadoc] Executing >FULL_PATHNAME_TO_JAVADOC>. In the second case it only talks about javadoc without any pathname and the debug output will show your exceptions later.
I assume that your case is the second one, but please check it!
If Eclipse / Ant don't know the location of javadoc you first should simplify things by taking Eclipse out of the equation: Use the command line and check that typing these commands do not result in in a "command not found" message:
java
javac
javadoc
I assume that the first one is OK (after all you can run Eclipse as shown in you stacktraces). If the second and third command are not found, you have not installed an JDK but only a JRE on your computer. Install one and restart Eclipse.
If on the other hand javac is found but javadoc not, then your JDK is broken.
If both javac and javadoc are found then Eclipse simply does not know about it. But before going back to Eclipse type a last command in the command shell:
readlink -m $(which javadoc)/../..
Remember the path readlink gives you.
In Eclipse goto "Window -> Preferences -> Java -> Installed JREs". In the list select the entry with the checked checkbox and press "edit". If the line "JRE home" is not the same as the path readlink gave you, then most likely your Eclipse is configured to use only a local JRE but not your installed JDK.
If that's the case then cancel that "Edit" dialog, press "Add", select "Standard VM" and enter the path readlink gave you. After entering that path correctly Eclipse should fill out the other fields for you, hence you can just say "OK". Back in the "Installed JRE" list tick on the new item.
After that the javadoc task per se should start.
EDIT
However you need some more adjustments:
First: In this part:
<packageset dir="src/main">
<include name="java/**"/>
</packageset>
you are mixing the source directoy and the package parts. It should read:
<packageset dir="src/main/java">
</packageset>
Also javadoc likes to have access to referenced classes. Therefore you should add the same classpath to javadoc as you used for compiling your code. So add an appropriate <classpath> section right after </packageset>. This will take care of the "package xyz does not exist" warnings.
It looks like ant is failing to find the javadoc binary. I don't think ant uses the defined PATH to find the javadoc binary (the docs says that it uses the same JDK that ant uses).
Some of the things I would try are:
Add the executable attribute to the task, to point to a javadoc binary (I'm not saying this is a correct solution, but if it works, it means that there's a problem with the location from where ant is looking by default).
Ensure that your JAVA_HOME and PATH points to a JDK rather than JRE
Ensure that your JAVA_HOME points to the same java installation that your PATH points to.
I would change these lines in your build.xml :
<packageset dir="src/main/java">
<include name="**" />
</packageset>
I have a ant target, xml file in my TFS project folder. the project folder is bound with TFS(Team Foundation Server). My problem is when ever i try to build the project by running the ant target in that TFS bound location it fails. it gives the following failure.
> ria_ant_build.xml:435: Error running C:\Program Files\Java\jdk1.6.0_20\bin\javac.exe compiler
at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.
java:508)
at org.apache.tools.ant.taskdefs.compilers.JavacExternal.execute(JavacExternal.java:61)
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1153)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:930)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.6.0_20\bin\javac.exe": CreateProcess erro
r=87, The parameter is incorrect
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495)
at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.
java:505)
... 19 more
Caused by: java.io.IOException: CreateProcess error=87, The parameter is incorrect
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 24 more
but when i copy the project to a different location and remove the read only attribute from the folder the ant target runs without any error and I'm getting a deploy-able artifact. but even when i remove the read only attribute from the TFS folder i could not build the ant target.It seems like the problem exist on the TFS location it self. :(
can some one suggest me a method to solve this problem. I have to stay in the TFS location you guys know the reason i assume :)
--
Thanks & Regards,
Rangana
From your question it's hard to figure out what really causes your problem.
Perhabs, your ant call length is too long and even longer than the max command prompt line (that's 8191 characters in the latest versions of Windows). As question Fail to launch application (CreateProcess error=87), can't use shorten classpath workaround says you may consider "to shorten folder names, reduce depth of folder trees, using parameter files, etc".
Try to run ant with the -debug option to see the specific command-line parameters of your build call inside the TFS workspace. In that way you can estimate the total length of the call.
Playing around with creating a NetBeans plugin but I am making very little progress since the process of installing the module fails. What I am doing is right-clicking on the and choosing the 'Install/Reload in Development IDE' option and it fails with the following exception:
Enabling StandardModule:org.willcodejavaforfood.com jarFile: /Users/Erik/NetBeansProjects/module2/build/cluster/modules/org-willcodejavaforfood-com.jar...
java.io.IOException: Cannot enable StandardModule:org.willcodejavaforfood jarFile: /Users/Erik/NetBeansProjects/module2/build/cluster/modules/org-willcodejavaforfood.jar; problems: [Java > 1.6]
at org.netbeans.core.startup.ModuleSystem.deployTestModule(ModuleSystem.java:358)
at org.netbeans.core.startup.TestModuleDeployer.deployTestModule(TestModuleDeployer.java:68)
at org.netbeans.modules.apisupport.ant.InstallModuleTask.execute(InstallModuleTask.java:77)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor176.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:273)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:499)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
Using NetBeans 6.5 and running Java 1.6 on Mac OS X 10.5.6
Apperently this is a NetBeans issue for Mac OS X...
Answer from netbeans forums
If you make a new NetBeans module project and simply run that does it work? (trying to narrow the issue down, and eliminating anything but the absolute basics is a good place to start)
Looks like your target platform is set to JDK 5 but your module is built against JDK 6.