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>
Related
Following this post, I am using the following steps to compile the parser/lexer from this repository:
export CLASSPATH=".:/usr/local/Cellar/antlr/<version>/antlr-<version>-complete.jar:$CLASSPATH"
antlr <grammarName>.g4 -o <someFolder>/
javac <someFolder>/<grammarName>*.java
but when I use the instructions here:
grun <someFolder>/<grammarName> tokens -tokens < <inputFile>
I get this error messages:
Exception in thread "main" java.lang.NoClassDefFoundError: IllegalName: <someFolder>/<grammarName>Lexer
at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:889)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1014)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:825)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:723)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:646)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:604)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.antlr.v4.gui.TestRig.process(TestRig.java:129)
at org.antlr.v4.gui.TestRig.main(TestRig.java:119)
I would appreciate if you could help me know what is the problem and how I can resolve it.
I don’t see where you’ve specified a package name, so now your Java classes are located in <someFolder>. Be sure to compile them in that folder.
Then you’ll need to add that folder to your classpath (probably instead of “.”)
Try adding <someFolder> into the CLASSPATH you’re exporting. Then leave it off of your grun command line.
Java will only load classes from the Classpath (it’s a security thing). When TestRig runs, it attempts to load your class by building the Java class name it would have produced for you Parser (and Java will have to find that class somewhere in the classpath).
Your could modify the grun alias to allow for you to specify a directory to search for your classes, and use the -cp option on the Java command, but that’s probably more trouble than just adding it to you classpath that you’re using for this testing.
The project I work on (at work) is written in Java and using Java 6. We are trying to migrate to OpenJDK8.
We must use Eclipse Indigo for it (it's part of the project). After reading some of the previous threads I followed the steps of how to migrate.
The steps I followed:
Going to Windows -> Preferences -> Java -> Installed JRE's. There I clicked add and choose the path to an installed version 1.8.0 of Java.
Then I went to Project -> Properties -> Java Build Path -> Libraries. There I choose JRE System Library and clicked edit. In Alternate JRE I choose 1.8.0.
Then I went to Build -> External tools configuration -> JRE. In the Separate JRE section I choose 1.8.0.
Then I got an error (not compiled or run time error - just eclipse shows with red mark) in a Java file which was opened: (The error occurred after the second step)
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
Part of the code:
final String arg = getOption(ArgNames.JOB);
if (arg.contains("~~")) {
return arg.split("~~")[1];
} else {
return arg;
}
It says the error because of arg.contains("~~"). I have read all the previous threads about that error but they suggest to go back to the old Java version (Although we would like to move to OpenJDK8).
I tried to build and it actually does not has any compilation errors. I'm not sure if I should be happy or sad about it, because I'm not sure if I actually built it properly with OpenJDK8.
To sum it up I'll try to ask some direct questions:
How can I verify that I build it with the right version?
How should I make sure that all of the features are working as they were with Java 6?
How to fix that Eclipse red mark error that I pointed out?
EDIT: I clicked restart to restart the Eclipse and now when I try to build it, it fails. The first part of the log file looks as follows:
!SESSION 2019-04-18 18:45:36.356 -----------------------------------------------
eclipse.buildId=M20120208-0800
java.version=1.8.0
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -application org.eclipse.ant.core.antRunner -buildfile tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009//scripts/productBuild/productBuild.xml -Dtimestamp=2010
Command-line arguments: -application org.eclipse.ant.core.antRunner -buildfile tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009//scripts/productBuild/productBuild.xml -Dtimestamp=2010
!ENTRY org.eclipse.osgi 4 0 2019-04-18 18:45:53.567
!MESSAGE Application error
!STACK 1
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:513)
at org.eclipse.ant.core.AntRunner.start(AntRunner.java:600)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/productBuild/productBuild.xml:43: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/build.xml:105: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/templates/headless-build/customTargets.xml:12: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/productBuild/allElements.xml:20: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/genericTargets.xml:118: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/genericTargets.xml:123: The following error occurred while executing this line:
tools/workspace/buildFiles/features/org.eclipse.build.container.feature/build.xml:30: The following error occurred while executing this line:
tools/workspace/buildFiles/features/org.eclipse.build.container.feature/build.xml:16: The following error occurred while executing this line:
tools/workspace/buildFiles/features/com.feature/build.xml:278: The following error occurred while executing this line:
tools/workspace/buildFiles/features/com.feature/build.xml:109: The following error occurred while executing this line:
tools/workspace/buildFiles/plugins/com.testmanagement/build.xml:235: The following error occurred while executing this line:
tools/workspace/buildFiles/plugins/com.testmanagement/build.xml:196: Compile failed; see the compiler error output for details.
I guess some of the featuers are failing. I know that Sun class has changed in version 8. Maybe it's the reason?
EDIT2: From previous threads I have learned that Eclipse Indiago does not work well with Java 8. So I moved to Luna. But most of the files now fail because my project uses Indiago.
Some of the errors:
The import org.eclipse cannot be resolved
The import org.osgi cannot be resolved
The import junit cannot be resolved
How to solve those errors?
EDIT3: As I understand, Indigo does not supports Java 8. So I moved to Luna. But now every plugin fails. There are a bunch of paths that does not exists in Windows -> Preferences -> Plug-in Development -> Target Platform -> Running Platform -> edit. The project uses Indigo and not Luna so the paths does not exists:
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.presentations.r21.source_3.2.200.I20100517-1500.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.source_3.7.0.v20110928-1505.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.views.log.source_1.0.200.v20110404.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.views.properties.tabbed.source_3.5.200.v20110928-1505.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.views.source_3.6.0.v20110928-1505.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.workbench.compatibility.source_3.2.100.I20110413-1600.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.workbench.source_3.7.1.v20120104-1859.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.workbench.texteditor.source_3.7.0.v20110928-1504.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.configurator.source_3.3.100.v20100512.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.core.source_3.2.500.v20110330.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.scheduler.source_3.2.300.v20100512.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.ui.source_3.2.300.v20100512.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.core.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.integration.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.library.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.text.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.junit.source_3.8.2.v3_8_2_v20100427-1100.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.junit.source_4.8.2.v4_8_2_v20110321-1705.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.mortbay.jetty.server.source_6.1.23.v201012071420.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.mortbay.jetty.util.source_6.1.23.v201012071420.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.objectweb.asm.source_3.3.1.v201105211655.jar
It became a long thread and I'm sorry for that. How to solve it?
From your comment you state you are using Indigo. Java 8 support wasn't introduced until Luna, although Kepler could support it with a patch.
https://www.eclipse.org/lists/eclipse.org-committers/msg00948.html
Although here is a blog of someone who got it to work with Juno:
https://tuhrig.de/java-8-in-eclipse-juno/
Here's a stack overflow answer that says they couldn't get it to work with Indigo.
https://stackoverflow.com/a/40053177/3501286
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");
When I try to launch the RNetLogo from R using the function NLStart(). I get messages about java and the GUI does not open. I am using MacOsX 10.9.5 64-bit, NetLogo 5.1.0, and R 3.1.1.
> library(rJava)
> library(RNetLogo)
> nl.path <- "/Applications/NetLogo\ 5.1.0/NetLogo\ 5.1.0.app"
> NLStart(nl.path, nl.version=5, gui=FALSE)
java.lang.NoClassDefFoundError: org/nlogo/workspace/Controllable
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
Caused by: java.lang.ClassNotFoundException
at RJavaClassLoader.findClass(RJavaClassLoader.java:383)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 2 more
After that I try with "JGR and Deducer and deducer extras”.
The code and errors are:
> install.packages(c("JGR","Deducer","DeducerExtras”))
> Sys.setenv(NOAWT=1)
> library(JGR)
> Sys.unsetenv("NOAWT")
> JGR()
When start JGR the code is:
Loading required package: JGR
Loading required package: rJava
Loading required package: JavaGD
Loading required package: iplots
starting httpd help server ... done
Loading required package: RNetLogo
Loading required package: DeducerExtras
Loading required package: Deducer
Loading required package: ggplot2
Use suppressPackageStartupMessages to eliminate package startup messages.
Loading required package: car
Loading required package: MASS
Attaching package: ‘Deducer’
Loading required package: irr
Loading required package: lpSolve
> nl.path<-"/users/Pabolo/Applications/NetLogo\ 5.1.0/NetLogo.jar"
> NLStart(nl.path)
Error on setwd(nl.path) : you can not change the working directory.
With nl.path be the path to the app dir.
There are some errors.
I running all these over JGR().
> nl.path<-"/Applications/NetLogo\ 5.1.0"
> NLStart(nl.path)
Warning: ch.randelshofer.quaqua.util.OSXPreferences failed to load /Users/Pabolo/Library/Preferences/.GlobalPreferences.plist
java.io.IOException: parseReal: unsupported byte count:128
at ch.randelshofer.quaqua.util.BinaryPListParser.parseReal(BinaryPListParser.java:703)
at ch.randelshofer.quaqua.util.BinaryPListParser.parseObjectTable(BinaryPListParser.java:424)
at ch.randelshofer.quaqua.util.BinaryPListParser.parse(BinaryPListParser.java:315)
at ch.randelshofer.quaqua.osx.OSXPreferences.readPList(OSXPreferences.java:176)
at ch.randelshofer.quaqua.osx.OSXPreferences.updateCache(OSXPreferences.java:99)
at ch.randelshofer.quaqua.osx.OSXPreferences.ensureCached(OSXPreferences.java:90)
at ch.randelshofer.quaqua.osx.OSXPreferences.get(OSXPreferences.java:79)
at ch.randelshofer.quaqua.osx.OSXPreferences.getString(OSXPreferences.java:45)
at ch.randelshofer.quaqua.BasicQuaquaLookAndFeel.initSystemColorDefaults(BasicQuaquaLookAndFeel.java:151)
at ch.randelshofer.quaqua.leopard.Quaqua15LeopardLookAndFeel.initSystemColorDefaults(Quaqua15LeopardLookAndFeel.java:208)
at ch.randelshofer.quaqua.BasicQuaquaLookAndFeel.getDefaults(BasicQuaquaLookAndFeel.java:76)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:520)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:564)
at org.nlogo.swing.Utils.setSystemLookAndFeel(Utils.java:41)
at org.nlogo.app.App.<init>(App.scala:302)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.picocontainer.injectors.AbstractInjector.newInstance(AbstractInjector.java:147)
at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:332)
at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:272)
at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:354)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:692)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:646)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:671)
at org.nlogo.app.App$.main(App.scala:140)
at org.nlogo.app.App.main(App.scala)
at nlcon.NLink_v5.<init>(NLink_v5.java:96)
at org.rosuda.JRI.Rengine.rniRunMainLoop(Native Method)
at org.rosuda.JRI.Rengine.run(Rengine.java:640)
unable to find translation for: edit.viewSettings.2D.frameRate in GUI_Strings for locale: es
unable to find translation for: edit.viewSettings.2D.frameRate.info in GUI_Strings for locale: es
>
You have to change your path to: nl.path <- "/Applications/NetLogo 5.3/app".
They have changed the directory structure so that the netlogo jar file is now in an 'app' subdirectory.
Source: https://stackoverflow.com/a/34837036/468305
Hope that helps, it worked for me.
It says you can not change your working directory. Maybe start a new session. Also one of your backslashes is going the wrong way.
To find your NetLogo path try file.choose() and then navigate to the NetLogo Jar file. Then when you open the path to file will show in R studios console. Copy the file path into the NLStart command which should look something like below.
file.choose()
NLStart("C:\\Program Files\\NetLogo 6.2.0\\app", gui = TRUE, nl.jarname = "netlogo-6.2.0.jar")
Finally, make sure your Java, NetLogo and R are all running on 64 bit (works for me) or 32 bit but try not to mix. Finally try and run code directly from R GUI instead of RStudio. This helped the first time I opened Netlogo with R.
I have a youtube video (https://www.youtube.com/watch?v=zWMdaTEPTOc) explaining how to open NetLogo from R and all my functional code (August 2021) can be found here.
I am trying to run a java program bundled in the jar named easyflow-gui.jar using cmd:
java -classpath "." -jar easyflow-gui.jar
The working directory is the directory containing all relevant libraries.
The content of the Manifest file of the jar file I am trying to run is:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_32-b27 (Sun Microsystems Inc.)
Main-Class: easyflow.custom.jgraphx.editor.SchemaEditor
The result of this attempt is:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mxgraph/util/mxEventSource$mxIEventListener
Caused by: java.lang.ClassNotFoundException: com.mxgraph.util.mxEventSource$mxIEventListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: easyflow.custom.jgraphx.editor.SchemaEditor. Program will exit.
Question: which one of the classes is actually not found: the mxEventSource$mxIEventListener or the main class easyflow.custom.jgraphx.editor.SchemaEditor ?
Edit 1:
I checked the folder and extracted the jars and I find both classes available (bundled into its respective jars in the working dir):
$ls easyflow/custom/jgraphx/editor/SchemaEditor*
easyflow/custom/jgraphx/editor/SchemaEditor$1.class
easyflow/custom/jgraphx/editor/SchemaEditor$2.class
easyflow/custom/jgraphx/editor/SchemaEditor.class
easyflow/custom/jgraphx/editor/SchemaEditor.java
$ls com/mxgraph/util/mxEventSource*
com/mxgraph/util/mxEventSource$mxIEventListener.class
com/mxgraph/util/mxEventSource.class
You cannot specify "." for the classpath if you want to include a jar file, it has to be a colon-separated list of jar files or directories (or semicolon-separated, depending on the operating system). Try java -help to get a description of the command line options.
Also if I remember correctly -jar and -classpath do not work together, so you have to use -classpath alone and specify the main class explicitly.
Try something like
java -cp easyflow-gui.jar:foo.jar:bar.jar easyflow.custom.jgraphx.editor.SchemaEditor
... where foo.jar and bar.jar are the "other relevant libraries".
If you read the exception properly, you will see that the cause of the error:
Caused by: java.lang.ClassNotFoundException: com.mxgraph.util.mxEventSource$mxIEventListener
You didn't include the jar file that contains the com.mxgraph.util.mxEventSource$mxIEventListener in your classpath. From a quick Google search, you will need jGraph library.
I hope this helps.
The default classpath is the current working directory.
So, if you already have the jar in your current working directory, you dont need to specify the classpath explicitly.
The following command should work
java -jar easyflow-gui.jar