Option-2 : Install via Choco and use with Command Line
Choco install
For windows users, majkinetor introduced a way to install plantuml and its dependencies easily. Run cmd.exe as Administrator, and run two commands as follows (the first command is not needed and will fail if you already have chocolatey installed).
var plantumlEncoder = require('plantuml-encoder')
var encoded = plantumlEncoder.encode('A -> B: Hello')
console.log(encoded) // SrJGjLDmibBmICt9oGS0var url = 'http://www.plantuml.com/plantuml/img/' + encoded
var decoded = plantumlEncoder.decode(encoded)
console.log(decoded)
CE204 Object-Oriented Programming
Plantuml How to use it online?
Javascript Decoder Example
var plantumlEncoder = require('plantuml-encoder')
var plain = plantumlEncoder.decode('UDfpLD2rKt2oKl18pSd91m0KGWDz')
console.log(plain) // A -> B: Hello
CE204 Object-Oriented Programming
Plantuml How to use it online?
Simple HEX format
If you find Deflate and Brotli too complex, you can try the HEX format. In that case, you just have to encode each character in hexadecimal format.
With the proxy service, the source description of the diagram can be fetched by the PlantUML Server from a remote document.
The proxy service uses the following URL scheme: /plantuml/proxy?src=RESOURCE&idx=INDEX&fmt=FORMAT
RESOURCE is the complete URL of the document which contains the diagram description (with the @startxxx and @endxxx tags), it could be a .html or a .txt file.
INDEX is optional, it specifies the occurrence (starting at 0) of the diagram description that will be parsed when there are more than one diagram descriptions in the remote document. It defaults to zero.
FORMAT is optional, it specifies the format to return. Supported values are: png, svg, eps, epstext and txt. Default is png,
Many plugins take advantage of the online web server to generate images.
For some reasons (security, performance...) you may need to use your own local server instead. This is possible thanks to the PlantUML Server which is available here.
However, installing and configuring a full webserver may be too complex for some users so we have decided to integrate a tiny webserver inside plantuml.jar.
This means that you only need a Java Runtime Environment and plantuml.jar to run this very simple web server.
The server is really basic. It only understands GET requests with following patterns:
/plantuml/png/xyz....
/plantuml/svg/xyz....
The server will return a PNG or SVG image.
The server will return a 404 error if the request is not understood.
The server will return a 500 error if the image cannot be generated.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
PlantUML PicoWeb Server
Those GET requests are used by various PlantUML plugins. Once you have launched your server, you can simply test it. With any web browser, you just have to point to: http://127.0.0.1:8080.
This way, you can very easily use any plugins which need some PlantUML HTTP server without the official online server.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
PlantUML Server
You can use PlantUML using the online web service to generate images on-the-fly. A online demonstration is available at http://www.plantuml.com/plantuml, but you can also install it on your own JEE web application server.
This command will search for @startXYZ and @endXYZ into .txt, .tex, .java, .htm, .html, .c, .h, .cpp, .apt, .pu, .puml, .hpp, .hh or .md files of the c:/directory1 and c:/directory2 directories.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Configuration File
You can also provide a configuration file which will be included before each diagram:
Sounds like magic! No, merely clever engineering :-)
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Metadata
After all preprocessing (includes etc), PlantUML saves the diagram's source code in the generated PNG Metadata in the form of encoded text.
If you does not want plantuml to save the diagram's source code in the generated PNG Metadata, you can during generation use the option -nometadata to disable this functionality (To NOT export metadata in PNG/SVG generated files).
It is possible to retrieve this source with the -metadata option. This means that the PNG is almost "editable": you can post it on a corporate wiki where you cannot install plugins, and someone in the future can update the diagram by getting the metadata, editing and re-uploading again. Also, the diagram is stand-alone.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Metadata
Conversely, the -checkmetadata option checks whether the target PNG has the same source and if there are no changes, doesn't regenerate the PNG, thus saving all processing time. This allows you to run PlantUML on a whole folder (or tree with the -recursive option) incrementally.
Sounds like magic! No, merely clever engineering :-)
Unfortunately this option works only with local files. It doesn't work with -pipe so you cannot fetch a URL with eg curl and feed the PNG to PlantUML.
However, the Plantuml server has a similar feature, where it can get a PNG from a URL and extract its metadata.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command line
You can run PlantUML using the command line. (See running for ways to run PlantUML from various other tools and workflows).The most basic way to run it is:
java -jar plantuml.jar file1 file2 file3
This will look for @startXYZ into file1, file2 and file3. For each diagram, a .png file will be created.For processing a whole directory, you can use:
This command will search for @startXYZ and @endXYZ into .txt, .tex, .java, .htm, .html, .c, .h, .cpp, .apt, .pu, .puml, .hpp, .hh or .md files of the c:/directory1 and c:/directory2 directories.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Wildcards
You can also use wildcards :
For a single character, use ?
For zero or more characters, use *
For zero or more characters, (including / or \), use a double **
So to process any .cpp files in all directories starting by dummy :
java -jar plantuml.jar "dummy*/*.cpp"
And to process any .cpp files in all directories starting by dummy, and theirs subdirectories :
java -jar plantuml.jar "dummy*/**.cpp"
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Excluded files
You can exlude some files from the process using the -x option:
If you recurse into several directory, there is a slight difference if you provide an absolute or a relative path for this output directory:
An absolute path will ensure that all images are output to a single, specific, directory.
If you provide a relative path then the images is placed in that directory relative to the location of the input file, not the current directory (note: this applies even if the path begins with a .). When Plantuml processes files from multiple directores then the corresponding directory structure is created under the computed output directory.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Types of Output File
Images for your diagrams can be exported in a variety of different formats. By default the format will be a PNG file but another type can be selected using the following extensions:
When there are some errors in diagrams the command returns an error (-1) exit code. But even if some diagrams contain some errors, all diagrams are generated, which can be time consuming for large project.
You can use the -failfast flag to change this behavior to stop diagram generations as soon as one error occurs. In that case, some diagrams will be generated, and some will not.
There is also a -failfast2 flag that does a first checking pass. If some error is present, no diagram will be generated at all. In case of error, -failfast2 runs even faster than -failfast, which may be useful for huge project.
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Standard report [stdrpt]
Using the -stdrpt (standard report) option, you can change the format of the error output of your PlantUML scripts.
With this option, a different error output of your diagram is possible:
Examples, with the bad file file1.pu, where as is written aass:
@startuml
participant "Famous Bob" aass Bob
@enduml
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Standard report [stdrpt]
Without any option
java -jar plantuml.jar file1.pu
The error output is:
Error line 2 in file: file1.pu
Some diagram description contains errors
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Standard report [stdrpt]
-stdrpt option
java -jar plantuml.jar -stdrpt file1.pu
The error output is:
file1.pu:2:error:Syntax Error?
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Standard report [stdrpt]
-stdrpt:1 option
java -jar plantuml.jar -stdrpt:1 file1.pu
The error output is:
protocolVersion=1
status=ERROR
lineNumber=2
label=Syntax Error?
Error line 2 in file: file1.pu
Some diagram description contains errors
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Standard report [stdrpt]
-stdrpt:2 option (like -stdrpt)
java -jar plantuml.jar -stdrpt:2 file1.pu
The error output is:
file1.pu:2:error:Syntax Error?
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
You can have a help message by launching :
java -jar plantuml.jar -help
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
This will output:
Usage: java -jar plantuml.jar [options] -gui
(to execute the GUI)
or java -jar plantuml.jar [options] [file/dir] [file/dir] [file/dir]
(to process files or directories)
You can use the following wildcards in files/dirs:
* means any characters but '\'
? one and only one character but '\'
** means any characters (used to recurse through directories)
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
where options include:
-gui To run the graphical user interface
-tpng To generate images using PNG format (default)
-tsvg To generate images using SVG format
-teps To generate images using EPS format
-tpdf To generate images using PDF format
-tvdx To generate images using VDX format
-txmi To generate XMI file for class diagram
-tscxml To generate SCXML file for state diagram
-thtml To generate HTML file for class diagram
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
-ttxt To generate images with ASCII art
-tutxt To generate images with ASCII art using Unicode characters
-tlatex To generate images using LaTeX/Tikz format
-tlatex:nopreamble To generate images using LaTeX/Tikz format without preamble
-o[utput] "dir" To generate images in the specified directory
-DVAR1=value To set a preprocessing variable as if '!define VAR1 value' were used
-Sparam1=value To set a skin parameter as if 'skinparam param1 value' were used
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
-Ppragma1=value To set pragma as if '!pragma pragma1 value' were used
-I\path\to\file To include file as if '!include file' were used
-I\path\to\*.puml To include files with pattern
-theme xxx To use a specific theme
-charset xxx To use a specific charset (default is windows-1251)
-e[x]clude pattern To exclude files that match the provided pattern
-metadata To retrieve PlantUML sources from PNG images
-nometadata To NOT export metadata in PNG/SVG generated files
-checkmetadata Skip PNG files that don't need to be regenerated
-version To display information about PlantUML and Java versions
-v[erbose] To have log information
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
-quiet To NOT print error message into the console
-debugsvek To generate intermediate svek files
-h[elp] To display this help message
-testdot To test the installation of graphviz
-graphvizdot "exe" To specify dot executable
-p[ipe] To use stdin for PlantUML source and stdout for PNG/SVG/EPS generation
-encodesprite 4|8|16[z] "file" To encode a sprite at gray level (z for compression) from an image
-computeurl|-encodeurl To compute the encoded URL of a PlantUML source file
-decodeurl To retrieve the PlantUML source from an encoded URL
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
-syntax To report any syntax error from standard input without generating images
-language To print the list of PlantUML keywords
-checkonly To check the syntax of files without generating images
-failfast To stop processing as soon as a syntax error in diagram occurs
-failfast2 To do a first syntax check before processing files, to fail even faster
-noerror To skip images when error in diagrams
-duration To print the duration of complete diagrams processing
-nbthread N To use (N) threads for processing
-nbthread auto To use 4 threads for processing
-timeout N Processing timeout in (N) seconds. Defaults to 15 minutes (900 seconds).
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
-author[s] To print information about PlantUML authors
-overwrite To allow to overwrite read only files
-printfonts To print fonts available on your system
-enablestats To enable statistics computation
-disablestats To disable statistics computation (default)
-htmlstats To output general statistics in file plantuml-stats.html
-xmlstats To output general statistics in file plantuml-stats.xml
-realtimestats To generate statistics on the fly rather than at the end
-loopstats To continuously print statistics about usage
-splash To display a splash screen with some progress bar
-progress To display a textual progress bar in console
CE204 Object-Oriented Programming
Plantuml How to use it offline?
Command-Line Options and Help
-pipeimageindex N To generate the Nth image with pipe option
-stdlib To print standard library info
-extractstdlib To extract PlantUML Standard Library into stdlib folder
-filedir xxx To behave as if the PlantUML source is in this dir (only affects '-pipe' and PicoWeb 'POST /render')
-filename "example.puml" To override %filename% variable
-preproc To output preprocessor text of diagrams
-cypher To cypher texts of diagrams so that you can share them
-picoweb To start internal HTTP Server. See https://plantuml.com/picoweb
If needed, you can setup the environment variable GRAPHVIZ_DOT
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
PlantUML is integrated in a variety of external tools. See command-line for options to run it from the command line.
SET GRAPHVIZ_DOT="C:\Program Files\Graphviz\bin\dot.exe"
SET DOXYGEN_EXE="C:\Program Files\doxygen\bin\doxygen.exe"
SET SOURCE_DIR=..\source
SET DOCS_DIR=..\docs
SET DOC_IMG_PATH_UML=..\doxygen-plantuml\resources
SET DOC_IMG_PATH=../doxygen-plantuml/resources
:: SET STRIP_PATH="C:xx"
You need to install Java and the PlantUML's jar file, if you want to use this command. When using PlantUML in you have to download some more jar files,
for details see the PlantUML documentation. This also is valid for the <engine>s latex and math.
The location of the PlantUML file should be specified using PLANTUML_JAR_PATH. The other jar files should also reside in this directory.
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
The use of the <engine>ditaa is not possible in as PlantUML only supports the png format and doxygen requires, temporary, eps output.
Not all diagrams can be created with the PlantUML @startuml command but need another PlantUML @start... command.
This will look like @start<engine> where currently supported are the following <engine>s: uml, bpm, wire, dot, ditaa, salt, math, latex, gantt, mindmap, wbs, yaml, creole, json, flow, board and git. By default the <engine> is uml. The <engine> can be specified as an option.
Also the file to write the resulting image to can be specified by means of an option, see the description of the first (optional) argument for details. Of course only one <engine> can be specified and also the filename can only be specified once.
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
The first argument is optional and is for compatibility with running PlantUML as a preprocessing step before running doxygen, you can also add the name of the image file after \startuml and inside curly brackets as option, i.e.
@startuml{myimage.png} "Image Caption" width=5cm
Alice -> Bob : Hello
@enduml
When the name of the image is specified, doxygen will generate an image with that name. Without the name doxygen will choose a name automatically.
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
The second argument is optional and can be used to specify the caption that is displayed below the image. This argument has to be specified between quotes even if it does not contain any spaces. The quotes are stripped before the caption is displayed.
The third argument is also optional and can be used to specify the width or height of the image. For a description of the possibilities see the paragraph Size indication with the \image command.
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
Note
doxygen creates a temporary file that is automatically removed unless the DOT_CLEANUP tag is set to NO.
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
Here is an example of the use of the \startuml command.
/** Sender class. Can be used to send a command to the server.
* The receiver will acknowledge the command by calling Ack().
* \startuml
* Sender->Receiver : Command()
* Sender<--Receiver : Ack()
* \enduml
*/
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
class Sender
{
public:
/** Acknowledgment from server */
void Ack(bool ok);
};
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
/** Receiver class. Can be used to receive and execute commands.
* After execution of a command, the receiver will send an acknowledgment
* \startuml
* Receiver<-Sender : Command()
* Receiver-->Sender : Ack()
* \enduml
*/
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Doxygen?
Built-in Feature
class Receiver
{
public:
/** Executable a command on the server */
void Command(int commandId);
};
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Eclipse?
Information about the PlantUML Eclipse Plugin
The Eclipse Plugin is developed and maintained by Hallvard Trætteberg (many thanks for his work!).
Like the core library PlantUML itself, it is open source and the plugin is distributed under EPL license.
First, you have to display the PlantUML View (click the Window menu):
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Eclipse?
How to use it?
This view displays automatically the class you are working on:
CE204 Object-Oriented Programming
Plantuml Integrations with other tools
Plantuml How to integrate with Eclipse?
How to use it?
If you write some comment in PlantUML language, the corresponding diagram is automatically displayed. And if you have several comments with diagrams, it selects the one the cursor is in.
You can easily integrate PlantUML with your own code by adding plantuml.jar in your classpath.
CE204 Object-Oriented Programming
Calling PlantUML from Java
PNG generation from a String
If your diagram description is stored in a String, you can use the SourceStringReader class to generate some PNG file.
import net.sourceforge.plantuml.SourceStringReader;
OutputStream png = ...;
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";
SourceStringReader reader = new SourceStringReader(source);
// Write the first image to "png"
String desc = reader.outputImage(png).getDescription();
// Return a null string if no generation
CE204 Object-Oriented Programming
Calling PlantUML from Java
PNG generation from a File
If your diagram description is stored in a File, you can use the SourceFileReader class to generate some PNG file.
File source = ...;
SourceFileReader reader = new SourceFileReader(source);
List<GeneratedImage> list = reader.getGeneratedImages();
// Generated files
File png = list.get(0).getPngFile();
CE204 Object-Oriented Programming
Calling PlantUML from Java
SVG generation from a String
If your diagram description is stored in a String, you can use the SourceStringReader class to generate some SVG file.
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";
SourceStringReader reader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Write the first image to "os"
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();
// The XML is stored into svgfinal String svg = new String(os.toByteArray(), Charset.forName("UTF-8"));