How to call GraphViz from java

后端 未结 3 1503
深忆病人
深忆病人 2021-02-01 10:57

How to call GraphViz from java and how to call GraphViz functions using java? What are the necessary jar files that are to be included inorder to access the GraphViz library for

3条回答
  •  臣服心动
    2021-02-01 11:21

    I've answered similar question here: Calling Graphviz dot from Java

    You can use the Graphviz Java API class which is a wrapper for Runtime.exec(), this is if you have the dot binaries on the same server as your Java App.

    If you don't have dot installed on the server or if you are using an environment like Google AppEngine where you can't install dot binaries locally then you can use Graphviz Server, a lightweight Java based HTTP server, you still need to install the dot binaries on the server on which you run Graphviz Server.

    The following is a code example using the Graphviz Java API class

    // graphTypeis one of: pdf, svg, png, etc...
    
    private static final String TEMP_PATH = "/tmp/graph.";
    
    private File generateGraph(String dot, String graphType) {
    
        GraphViz gv = new GraphViz();
        gv.readString(dot);
    
        File out = new File(TEMP_PATH + graphType);   // Linux
    
        gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), graphType ), out );
    
        return out;
    }
    

提交回复
热议问题