How can I ask UMLGraph to generate a single diagram for all the underlying .java classes within a package ?
I am using UMLGraph along with Graphviz to generate a .png UML diagram file.
The command that I am running to geenrate a.dot file is :
java -jar C:/Program Files/Java/jdk1.7.0_80/lib/UmlGraph.jar -all -private A.java
This runs succesfully to geenrate a .dot file.
However,I wish to create a single UML diagram out of them ( They are all linked to eachother via java code).
The "uml-parser-test-1" (folder/package) contains all about 5 .java files and for that I am running
C:/Users/xyz > java -jar "C:/Program Files/Java/jdk1.8.0_60/lib/UmlGraph.jar" -all -private "D:/xyz/abcd/uml-parser-test-1/"
When I run above code , I get an error : UMLGRAPH ERROR - ILLEGAL PACKAGE NAME
Where am I going wrong
**EDIT:: 6th Oct**
There was an issue with umlgraph.jar path and I had corrected it. Thanks for pointing that out.
Now I am able to run the command you suggested without any errors. THe thing is my "Persons" package(folder) contains 4 java files(A,B,C,D.java). When I run the command, it generated .dot file on the command line and not in my file system.Moreover, it is incomplete as there is no information about classes :
Below is the trace of my command line .
C:\Users\xyz>java -classpath "C:/Program Files/Java/jdk1.8.0_60/lib/UmlGraph.jar;C:/Program Files/Java/jdk1.8.0_20/lib/tools.jar" org.umlgraph.doclet.UmlGraph -package -output - -sourcepath "C:/Program Files/Java/jdk1.8.0_60/lib/Persons" org.umlgraph.doclet
Loading source files for package org.umlgraph.doclet...
UmlGraph: warning - No source files for package org.umlgraph.doclet
Constructing Javadoc information...
UmlGraph: warning - No source files for package org.umlgraph.doclet
UMLGraph doclet version R5_7_2-3-gee82a7 started
Building general class diagram
#!/usr/local/bin/dot
#
# Class diagram
# Generated by UMLGraph version R5_7_2-3-gee82a7 (http://www.umlgraph.org/)
#
digraph G {
edge [fontname="arial",fontsize=10,labelfontname="arial",labelfontsize=10];
node [fontname="arial",fontsize=10,shape=plaintext];
nodesep=0.25;
ranksep=0.5;
}
2 warnings
Any idea, why it is not parsing the class details?
You must specify in the command line invocation the package name and the directory where its source code is located. The following example, when run in the UMLGraph directory, generates a diagram for the UMLGraph classes.
java -classpath "lib/UmlGraph.jar;C:\Program Files\Java\jdk1.8.0_20/lib/tools.jar" org.umlgraph.doclet.UmlGraph -package -output - -sourcepath src/main/java org.umlgraph.doclet | dot -Tpng -oumlgraph.png
Related
Please do not provide solutions using Maven, Gradle… I look for a CLI solution only. No jlink-based solution as well.
Given Open_My_type_module-1.0.jar as a preexisting compiled Java 9 module:
module Open_My_type_module { // module-info.java
exports Open_My_type_package;
opens Open_My_type_package;
}
The code in this module only declares the following class:
Open_My_type_package.My_type
I reuse this module into another one as follows:
module Access_My_type_module { // module-info.java
requires Open_My_type_module;
}
// Business code (for test only in a Main.java class):
Class<Open_My_type_package.My_type> c = Open_My_type_package.My_type.class;
Starting from the following structure:
THIRD_PARTY_MODULE >> Open_My_type_module-1.0.jar
src >> main >> java >> com >> X >> Access_My_type_package >> Main.java
src >> main >> java >> module-info.java
Compilation succeeds based the following line:
javac -d PRODUCTION_SOFTWARE --module-path THIRD_PARTY_MODULE src/main/java/com/X/Access_My_type_package/Main.java src/main/java/module-info.java
Next, before execution, I package my software as follows:
cd PRODUCTION_SOFTWARE
jar --create --verbose --file Access_My_type_module-1.0.jar --main-class com.X.Access_My_type_package.Main *
Packaging DOES NOT seem to « link » Open_My_type_module-1.0.jar in the final executable, but I check the inside of the packaged software:
jar --file=Access_My_type_module-1.0.jar --describe-module
Display (everything seems sound):
Access_My_type_module jar:file://./Access_My_type_module-1.0.jar/!module-info.class
requires Open_My_type_module
requires java.base mandated
contains com.X.Access_My_type_package
main-class com.X.Access_My_type_package.Main
Finally, execution fails with java.lang.NoClassDefFoundError from:
java --module-path THIRD_PARTY_MODULE -jar Access_My_type_module-1.0.jar
I believed that --module-path THIRD_PARTY_MODULE is enough to link Open_My_type_module-1.0.jar at execution time, but I keep the feeling that my packaging command is shaky. Beyond, I’m sure I’ve missed of a key issue about Java 9 modules… HELP WELCOME please!
Solution (below) is inspired from https://sites.google.com/a/athaydes.com/renato-athaydes/posts/guidetojava9-compilejarrun.
With Java modules, execution is better controlled using --module instead of -jar. So
java --module-path THIRD_PARTY_MODULE --module Access_My_type_module works fine!
Assumption: Access_My_type_module-1.0.jar must be located within THIRD_PARTY_MODULE along with Open_My_type_module-1.0.jar (for simplicity here). In short, java finds in the THIRD_PARTY_MODULE directory all the desired stuff.
Please note that --module required the module name (ie, Access_My_type_module) and
NOT the jar file name!
Please also note that Access_My_type_module-1.0.jar manifest has already been set up with a main class at packaging time... if not tell java which is the main class at execution time.
I have Ubuntu 16.04.
and downloaded a JDK with a tar.gz file extension and followed This wikihow to install it.
When I try to run a .jar game (like Minecraft) It works successfully, and I have netbeans downloaded that is connected to the same JDK and compiled some programs that i can run in terminal, But When I type :
./Hello_world.jar
Which is :
package main;
public class project {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
I get this output :
./Hello_world.jar: line 1: $'PK\003\004': command not found
./Hello_world.jar: line 2: $'\b.\020oK': command not found
./Hello_world.jar: line 3: syntax error near unexpected token `)'
./Hello_world.jar: line 3:-oK�}����META-INF/MANIFEST.MFM�1
�0��#��uHh Q���X� ��N1�Ҧ$)��7�(�p�ww
�A����|��}�1���ή�n��p<�Рŗ��:CpN~�s�ν�˚�3��%
��)���goPK`
Simple: JAR files aren't executables. You can only invoke binaries/scripts by telling your shell to ./command.
They are archives that contain compiled Java classes.
Thus you use them like:
java -jar somejar.jar
This starts a java virtual machine, and tells it to open the given JAR file. The JVM will then figure the "main" class to run from the meta information that can be backed into the JAR file - to then "run" that main class.
( assuming that the corresponding JAR file has been built in a why that allows running it like this. see here for details on how you enable this "easy way" of running a JAR file )
And just in case: with some scripting magic, you actually can turn a JAR file into a "binary", see here for example.
I get the following error:
org.dbpedia.spotlight.exceptions.ConfigurationException: Cannot find spotter file ../dist/src/deb/control/data/usr/share/dbpedia-spotlight/spotter.dict
at org.dbpedia.spotlight.model.SpotterConfiguration.<init>(SpotterConfiguration.java:54)
at org.dbpedia.spotlight.model.SpotlightConfiguration.<init>(SpotlightConfiguration.java:143)
at org.dbpedia.spotlight.web.rest.Server.main(Server.java:70)
Usage:
java -jar dbpedia-spotlight.jar org.dbpedia.spotlight.web.rest.Server [config file]
or:
mvn scala:run "-DaddArgs=[config file]"
Quick solution:
wget http://spotlight.dbpedia.org/download/release-0.5/dbpedia-spotlight-quickstart.zip
unzip dbpedia-spotlight-quickstart.zip
cd dbpedia-spotlight-quickstart/
./run.sh
Explanation:
DBpedia Spotlight looks for ~3.5M things of ~320 types in text and tries to disambiguate them to their global unique identifiers in DBpedia. Therefore it needs data files to accompany its jar. A minuscule example is distributed along with the source, but for real use cases you may need the larger files. After you've downloaded the files, you need to modify the configuration in server.properties with the correct path to the files. The error message you got tells you that one of the necessary files (spotter.dict) could not be found in the path you indicated in your server.properties.
More information available here:
https://github.com/dbpedia-spotlight/dbpedia-spotlight/wiki/Run-from-a-JAR
While trying to build a library that uses javah, I ran into a classpath issue. Apparently, the classpath is prefixed with the JDK path: please notice the final search path is wrong. How should I do instead?
elmarco#makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ CLASSPATH=$PWD javah -o javasasl.h -jni -verbose Sasl
error: cannot access Sasl
class file for Sasl not found
javadoc: error - Class Sasl not found.
[ Search Path: /usr/java/jdk1.6.0_24/jre/lib/resources.jar:/usr/java/jdk1.6.0_24/jre/lib/rt.jar:/usr/java/jdk1.6.0_24/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0_24/jre/lib/jsse.jar:/usr/java/jdk1.6.0_24/jre/lib/jce.jar:/usr/java/jdk1.6.0_24/jre/lib/charsets.jar:/usr/java/jdk1.6.0_24/jre/lib/modules/jdk.boot.jar:/usr/java/jdk1.6.0_24/jre/classes//home/elmarco/src/sasl/java/CyrusSasl ]
elmarco#makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ ls Sasl.java
Sasl.java
Thanks for your help!
(this is jdk1.6.0_24 on Fedora 14)
I usually avoid the CLASSPATH environment variable. This should work (and maybe without a problem):
javah -classpath .;<your-path> -o javasasl.h -jni -verbose Sasl
If don't need nothing but the local path, then you don't have to specify a -classpath option, . is the default value.
Note - you have to compile Sasl.java first. javah expects a class file. (Getting started)
I think it's simply a bug in how the javah outputs its actual classpath. What happens is that it has a bunch of places where it searches for built-in classes, and apart from them, it also uses the stuff in $CLASSPATH. When it prints the actual classpath used, they do something like this (pseudo code, assuming implicitEntries is a list of builtin classpath entries, and explicitEntries is a list of the the directories specified in $CLASSPATH):
print implicitEntries.join(pathSeparator) + explicitEntries.join(pathSeparator)
where it should have been
print implicitEntries.join(pathSeparator) + pathSeparator + explicitEntries.join(pathSeparator)
The following works fine for me:
$ ls
Sasl.class Sasl.java
$ javah -classpath . -o javasasl.h -jni -verbose Sasl [ Search Path: /usr/java/jdk1.6.0/jre/lib/resources.jar:/usr/java/jdk1.6.0/jre/lib/rt.jar:/usr/java/jdk1.6.0/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0/jre/lib/jsse.jar:/usr/java/jdk1.6.0/jre/lib/jce.jar:/usr/java/jdk1.6.0/jre/lib/charsets.jar:/usr/java/jdk1.6.0/jre/classes/. ]
[Creating file javasasl.h]
[search path for source files: [.]]
[search path for class files: [/usr/java/jdk1.6.0/jre/lib/resources.jar, /usr/java/jdk1.6.0/jre/lib/rt.jar, /usr/java/jdk1.6.0/jre/lib/sunrsasign.jar, /usr/java/jdk1.6.0/jre/lib/jsse.jar, /usr/java/jdk1.6.0/jre/lib/jce.jar, /usr/java/jdk1.6.0/jre/lib/charsets.jar, /usr/java/jdk1.6.0/jre/classes, /usr/java/jdk1.6.0/jre/lib/ext/dnsns.jar, /usr/java/jdk1.6.0/jre/lib/ext/localedata.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunpkcs11.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunjce_provider.jar, .]]
[loading ./Sasl.class]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Throwable.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Class.class)]
[done in 585 ms]
$ ls
javasasl.h Sasl.class Sasl.java
Now, since the header file generation doesn't seem to work for you... are you sure you have Sasl.class in the current directory? javah works with byte code files, not Java source files.
You show here, that the source file is available ...
(mingw32 *%)$ ls Sasl.java
Sasl.java
but missing is the class file (Sasl.class).
error: cannot access Sasl
class file for Sasl not found
Compile it first.
I'm prototyping a web page scraper using Rhino and Env-js. Nevermind that the documentation for both projects is atrocious... I'm trying to load up the File.java example class that is supplied with Rhino. For simplicity sake, I've got File.java, js.jar, jline.jar and env.rhino.1.2.js all in one directory. I've tried specifying the current directory using the classpath command line option, but still whenever I call defineClass("File") I get an error saying the class file isn't found. What am I doing wrong here??
$ ls -1
File.java
env.rhino.1.2.js
jline.jar
js.jar
$ java -cp .:js.jar:jline.jar jline.ConsoleRunner org.mozilla.javascript.tools.shell.Main -opt -1
Rhino 1.7 release 2 2009 03 22
js> defineClass("File")
js: "<stdin>", line 2: Class "File" not found.
at <stdin>:2
Don't you need to compile File.java before using it, as the classpath "." only makes sense if it contains some compiled class in it?