可视化工具gephi源码探秘
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了可视化工具gephi源码探秘相关的知识,希望对你有一定的参考价值。
在上篇《可视化工具gephi源码探秘(一)》中主要介绍了如何将gephi的源码导入myeclipse中遇到的一些问题,此篇接着上篇而来,主要讲解当下通过myeclipse导入gephi源码的可行性不高以及熟悉netbeans,并把原本基于netbeans平台开发的gephi源码导入进netbeans后启动正常运行的过程,其中有遇到的不少问题和相应的解决方法。
前日工作梗概(还是沿着想把源码导入myeclipse的思路):
经过从各大子模块的pom.xml中筛选出符合条件的jar包写入项目下的pom.xml文件后,maven dependency中虽然多了几十个jar包,表示确实已经下载下来了。但是项目还是大片的红色警告,主要原因还是没有正确导包。
通过观察发现报警较多的是由于org.openide所在的包没有引入,网上一通找后,在一个专门找jar包的网站上搜索了三个openide的版本jar包,但都遇到部分类不能中的方法还是报错,估计是因为导入的版本不对,但是网上确实找不到相应的jar了,所以这时想起之前通过maven在远程仓库上好像还下载了不少jar,去搜索了下还真有与openide相关的,导入到项目中还真是解决了导包报错的问题,于是针对项目中缺什么就去找什么,最终解决了所有报警的问题,这个问题是解决了,可是还有两大问题一直困扰着我:
一是根据各路消息得知gephi是在netbeans平台上开发的,而且在导包的过程中也注意到许多jar都烙上了netbeans的痕迹,担忧这样硬性移植到Myeclipse上会出现水土不服,当然表面上看没有报错;
二是通过在项目中搜索发现,项目中没有main函数,针对这一现象特地在网上搜索是否还有其他的入口标记,都是搜索未果。
下午的时候老大尝试直接把安装文件拷贝到项目中,把安装文件的gephi目录下的jar都换成源码中的各模块的源码,然后再编译,确实能编译过去,并且将部署的目录在.classpath中由bin改为了gephi/modules/目录下了,并将gephi.exe标记拷贝到bin目录下,这样是能够启动程序的,但是是不经过Myeclipse的,还是不能解决当前燃眉之急。
今日梗概:
今天一天都在困惑如何让源代码跑起来以及究竟是选择在myeclipse中跑还是在netbeans中跑。
工具版本简介:netbeans:6.9.1(起初下载的是netbeans8,但是需要jdk1.7,我的jdk版本是1.6所以选择netbeans6.9.1)、gephi:0.8.2、maven:2.0.6
我的足迹大致是这样的:
1.昨天晚上的时候发现还是应该尝试下netbeans的开发平台,各种权威官方网站只要提及gephi源码导入以及二次开始无一不提到netbeans,所以在选择平台的岔路口,我想都走着看看,不能一条道走到黑却发现前面是死胡同。
安装完netbeans后,开始捯饬着新建个maven项目,因为gephi源码中是有pom.xml文件的,选择的是maven netbeans模块套件选项:
但是提示我的maven版本太老(我的是2.0.6)确实是 有点旧了,后来就挪了一步,换成了项目需要的最低门槛2.0.7,点击下一步,开始配置一些参数信息:
点击完成后会先从maven的远程库中下载一些必要的jar包,因为此前是netbeans小白,所以新建项目后不知道如何拷贝gephi源码,只是讲pom.xml中的内容换成了gephi源码中自带的pom.xml,netbeans中的maven机制好像好myeclipse不太一样,在myeclipse中按下ctrl+s即可保存pom.xml同时也会下载jar包,netbeans就不会,所以我直接点击运行,这下好了,控制台打印出大量信息,都是写下载jar包的,具体信息就不贴了(插一句,怎么感觉怎么觉得netbeans的maven下载jar机制很好很强大,哪像myeclipse非你闹别扭一会中断一会报错),当然中途也报错了,说是对maven版本又有要求,需要3.0.3,。啥也别说了直接下个3.0.4吧,此后在运行估摸着jar包也下载的差不多了。
2.这些都不重要,重要的是gephi的源码还没有导入呢,眼前对他也是没辙,网上关于导入gephi源码到netbeans中的文章也是少之又少,后来时间不早,就回去嚼了嚼霍达的《穆斯林的葬礼》,还算有嚼头。今天一来就上谷歌上找了一通,看了半天也没什么进展,倒是更加确信在myeclipse下导入gephi源码似乎还是有点不合时宜,因为各路大神并没有直接否定说eclipse和myeclipse与导入gephi源码无缘,但是都很巧妙的说到,gephi是基于netbeans开发的,有很多组件一来与netbeans平台也很好用,所以推荐netbeans或者说明自己是用netbeans开发的(事实上,一天下来,真没发现哪个说用eclipse或是myeclipse导入源码成功并能够运行的)。搜索途中,发现有个gephi toolkit,看着拿捏不是很准的英文介绍应该是说是gephi的一个jar可以运行在任何java平台包括myeclipse中,于是下载了一个gephi-toolkit-0.8.7-all的jar,把里面的gephi-toolkit.jar放到在myeclipse中新建项目中,按照wikipedia上的介绍把一些例子挪到了项目中进行测试,其中一个用于生成随机图形的例子的代码如下:
1 package org.gephi; 2 3 import org.gephi.io.generator.plugin.DynamicGraph; 4 import org.gephi.io.generator.plugin.RandomGraph; 5 import org.gephi.io.importer.api.Container; 6 import org.gephi.io.importer.api.ContainerFactory; 7 import org.gephi.io.importer.api.ImportController; 8 import org.gephi.io.processor.plugin.AppendProcessor; 9 import org.gephi.io.processor.plugin.DefaultProcessor; 10 import org.gephi.project.api.ProjectController; 11 import org.gephi.project.api.Workspace; 12 import org.openide.util.Lookup; 13 14 public class GenerateGraph { 15 16 /** 17 * @param args 18 */ 19 public static void main(String[] args) { 20 21 //Init a project - and therefore a workspace 22 ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); 23 pc.newProject(); 24 Workspace workspace = pc.getCurrentWorkspace(); 25 26 //Generate a new random graph into a container 27 Container container = Lookup.getDefault().lookup(ContainerFactory.class).newContainer(); 28 RandomGraph randomGraph = new RandomGraph(); 29 randomGraph.setNumberOfNodes(500); 30 randomGraph.setWiringProbability(0.005); 31 randomGraph.generate(container.getLoader()); 32 33 //Append container to graph structure 34 ImportController importController = Lookup.getDefault().lookup(ImportController.class); 35 importController.process(container, new DefaultProcessor(), workspace); 36 37 //Generate another graph and append it to the current workspace 38 Container container2 = Lookup.getDefault().lookup(ContainerFactory.class).newContainer(); 39 RandomGraph randomGraph2 = new RandomGraph(); 40 randomGraph2.setNumberOfNodes(100); 41 randomGraph2.setWiringProbability(0.01); 42 randomGraph2.generate(container.getLoader()); 43 importController.process(container2, new AppendProcessor(), workspace); //Use AppendProcessor to append to current workspace 44 45 //Create new workspace 46 Workspace workspace2 = pc.newWorkspace(pc.getCurrentProject()); 47 pc.openWorkspace(workspace2); //Set as current workspace 48 49 //Generate dynamic graph into workspace 2 50 Container container3 = Lookup.getDefault().lookup(ContainerFactory.class).newContainer(); 51 52 DynamicGraph dynamicGraph = new DynamicGraph(); 53 dynamicGraph.generate(container3.getLoader()); 54 importController.process(container3, new DefaultProcessor(), workspace2); 55 56 } 57 58 59 }
成功运行后结果如下:
# Nodes loaded: 500
# Edges loaded: 578
# New Nodes appended: 0
# New Edges appended: 0
# Nodes loaded: 50
# Edges loaded: 47
# Edges loaded: 578
# New Nodes appended: 0
# New Edges appended: 0
# Nodes loaded: 50
# Edges loaded: 47
原本还是幻想着能够出来一个和gephi那样的界面,在这块啃了会,觉得没多大希望,而此时netbeans似乎一直在呼唤我。
3.在网上找了找关于netbeans和maven项目的关系,说是netbeans具有自动识别java项目、maven项目的功能,于是乎,点击文件->打开项目后,进入到我下载的源码目录下如图所示,我期望的gephi-0.8.2-beta没有独特的标示,但是之前下载的gephi-plugins-bootcamp-master倒是被识别出来了
先将该项目导入到netbeans中,点击运行,这时居然弹出gephi启动程序了,当时那种心情,在兴奋和犹豫要不要兴奋之间纠结,兴奋的是起码有一种途径可以通过程序跑出gephi,犹豫是因为这毕竟不是在myeclipse平台上,不是我熟悉的味道啊,这一历史性的突破可能就意味着下面我得好好喝netbeans处一段时间了。此外这也不是我要的通过源码启动程序,所以还是在源码上下功夫,搜索了下wikipedia上关于build gephi的介绍,看到了大体的导入的目录结构,于是再次点击打开项目,进入gephi-0.8.2-beta后豁然看见一个标记"ma"
可是后面总是显示“maven项目格式不正确”,几经百度、几经谷歌终不能解,于是又是陷入一个低谷。
4.这时又想到gephi这个项目似乎是没有main函数的,也就是说没有正常项目那样的入口,所以于如何启动从哪启动的问题也是一个心结,一顿搜索后发现问题总是很多,解决的相对较少,我不是第一个有这样疑惑的人,但也不是第一个知道这个问题答案的幸运儿,最终给我的感觉还是说netbeans可以指定一个启动入口或者说netbeans对于桌面应用程序具有特殊的处理使得不需要想一般程序一样通过main函数的讨论(当然,可能是偷偷用的,被封装起来而已)。之后来回往返于几个权威性的网页,看看大家的问题,结合自身的问题,灵机一动,咱换别的版本源码来瞧瞧,于是乎一口气下载了0.8.1-beta、0.8.0-alpha、0.8.0-beta、0.7.-alpha3和0.7-alpha4版本,逐一尝试,最终还是发现0.8.1是可以为我所用的,用过源码启动的阶段性问题算是解决了,启动的部分信息如下:
platform.download:
Using harness folder F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources/platform/harness
branding:
files-init:
release:
build:
org.gephi.desktop.mrufiles.api.taskdefs:
org.gephi.desktop.mrufiles.api.common-init:
org.gephi.desktop.mrufiles.api.projectized-common.basic-init:
org.gephi.desktop.mrufiles.api.basic-init:
org.gephi.desktop.mrufiles.api.files-init:
org.gephi.desktop.mrufiles.api.nbm-license-init:
org.gephi.desktop.mrufiles.api.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.gephi.desktop.mrufiles.api.init:
org.gephi.desktop.mrufiles.api.up-to-date:
org.gephi.desktop.mrufiles.api.compile:
org.gephi.desktop.mrufiles.api.jar-prep:
org.gephi.desktop.mrufiles.api.jar:
org.gephi.desktop.mrufiles.api.netbeans-extra:
org.gephi.desktop.mrufiles.api.javahelp:
org.gephi.desktop.mrufiles.api.module-auto-deps:
org.gephi.desktop.mrufiles.api.release:
org.gephi.desktop.mrufiles.api.module-xml-regular:
org.gephi.desktop.mrufiles.api.module-xml-autoload:
org.gephi.desktop.mrufiles.api.module-xml-eager:
org.gephi.desktop.mrufiles.api.chmod-executables:
org.gephi.desktop.mrufiles.api.verify-class-linkage:
0 file(s) have been successfully validated.
org.gephi.desktop.mrufiles.api.netbeans:
Generating information for Auto Update...
org.gephi.io.database.drivers.taskdefs:
org.gephi.io.database.drivers.common-init:
org.gephi.io.database.drivers.projectized-common.basic-init:
org.gephi.io.database.drivers.basic-init:
org.gephi.io.database.drivers.files-init:
org.gephi.io.database.drivers.nbm-license-init:
org.gephi.io.database.drivers.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.gephi.io.database.drivers.init:
org.gephi.io.database.drivers.up-to-date:
org.gephi.io.database.drivers.compile:
org.gephi.io.database.drivers.jar-prep:
org.gephi.io.database.drivers.jar:
org.gephi.io.database.drivers.netbeans-extra:
org.gephi.io.database.drivers.javahelp:
org.gephi.io.database.drivers.module-auto-deps:
org.gephi.io.database.drivers.release:
Copying 6 files to F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\build\\cluster
org.gephi.io.database.drivers.module-xml-regular:
……
Using harness folder F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources/platform/harness
branding:
files-init:
release:
build:
org.gephi.desktop.mrufiles.api.taskdefs:
org.gephi.desktop.mrufiles.api.common-init:
org.gephi.desktop.mrufiles.api.projectized-common.basic-init:
org.gephi.desktop.mrufiles.api.basic-init:
org.gephi.desktop.mrufiles.api.files-init:
org.gephi.desktop.mrufiles.api.nbm-license-init:
org.gephi.desktop.mrufiles.api.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.gephi.desktop.mrufiles.api.init:
org.gephi.desktop.mrufiles.api.up-to-date:
org.gephi.desktop.mrufiles.api.compile:
org.gephi.desktop.mrufiles.api.jar-prep:
org.gephi.desktop.mrufiles.api.jar:
org.gephi.desktop.mrufiles.api.netbeans-extra:
org.gephi.desktop.mrufiles.api.javahelp:
org.gephi.desktop.mrufiles.api.module-auto-deps:
org.gephi.desktop.mrufiles.api.release:
org.gephi.desktop.mrufiles.api.module-xml-regular:
org.gephi.desktop.mrufiles.api.module-xml-autoload:
org.gephi.desktop.mrufiles.api.module-xml-eager:
org.gephi.desktop.mrufiles.api.chmod-executables:
org.gephi.desktop.mrufiles.api.verify-class-linkage:
0 file(s) have been successfully validated.
org.gephi.desktop.mrufiles.api.netbeans:
Generating information for Auto Update...
org.gephi.io.database.drivers.taskdefs:
org.gephi.io.database.drivers.common-init:
org.gephi.io.database.drivers.projectized-common.basic-init:
org.gephi.io.database.drivers.basic-init:
org.gephi.io.database.drivers.files-init:
org.gephi.io.database.drivers.nbm-license-init:
org.gephi.io.database.drivers.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.gephi.io.database.drivers.init:
org.gephi.io.database.drivers.up-to-date:
org.gephi.io.database.drivers.compile:
org.gephi.io.database.drivers.jar-prep:
org.gephi.io.database.drivers.jar:
org.gephi.io.database.drivers.netbeans-extra:
org.gephi.io.database.drivers.javahelp:
org.gephi.io.database.drivers.module-auto-deps:
org.gephi.io.database.drivers.release:
Copying 6 files to F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\build\\cluster
org.gephi.io.database.drivers.module-xml-regular:
……
Generating information for Auto Update...
org.gephi.desktop.timeline.taskdefs:
org.gephi.desktop.timeline.common-init:
org.gephi.desktop.timeline.projectized-common.basic-init:
org.gephi.desktop.timeline.basic-init:
org.gephi.desktop.timeline.files-init:
org.gephi.desktop.timeline.nbm-license-init:
org.gephi.desktop.timeline.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.gephi.desktop.timeline.init:
org.gephi.desktop.timeline.up-to-date:
org.gephi.desktop.timeline.compile:
org.gephi.desktop.timeline.jar-prep:
org.gephi.desktop.timeline.jar:
org.gephi.desktop.timeline.netbeans-extra:
org.gephi.desktop.timeline.javahelp:
org.gephi.desktop.timeline.module-auto-deps:
org.gephi.desktop.timeline.release:
org.gephi.desktop.timeline.module-xml-regular:
org.gephi.desktop.timeline.module-xml-autoload:
org.gephi.desktop.timeline.module-xml-eager:
org.gephi.desktop.timeline.chmod-executables:
org.gephi.desktop.timeline.verify-class-linkage:
1 file(s) have been successfully validated.
org.gephi.desktop.timeline.netbeans:
Generating information for Auto Update...
org.netbeans.swing.dirchooser.taskdefs:
org.netbeans.swing.dirchooser.common-init:
org.netbeans.swing.dirchooser.projectized-common.basic-init:
org.netbeans.swing.dirchooser.basic-init:
org.netbeans.swing.dirchooser.files-init:
org.netbeans.swing.dirchooser.nbm-license-init:
org.netbeans.swing.dirchooser.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.netbeans.swing.dirchooser.init:
org.netbeans.swing.dirchooser.up-to-date:
org.netbeans.swing.dirchooser.compile:
org.netbeans.swing.dirchooser.jar-prep:
org.netbeans.swing.dirchooser.jar:
org.netbeans.swing.dirchooser.netbeans-extra:
org.netbeans.swing.dirchooser.javahelp:
org.netbeans.swing.dirchooser.module-auto-deps:
org.netbeans.swing.dirchooser.release:
org.netbeans.swing.dirchooser.module-xml-regular:
org.netbeans.swing.dirchooser.module-xml-autoload:
org.netbeans.swing.dirchooser.module-xml-eager:
org.netbeans.swing.dirchooser.chmod-executables:
org.netbeans.swing.dirchooser.verify-class-linkage:
0 file(s) have been successfully validated.
org.netbeans.swing.dirchooser.netbeans:
Generating information for Auto Update...
run:
run.run:
org.gephi.desktop.timeline.taskdefs:
org.gephi.desktop.timeline.common-init:
org.gephi.desktop.timeline.projectized-common.basic-init:
org.gephi.desktop.timeline.basic-init:
org.gephi.desktop.timeline.files-init:
org.gephi.desktop.timeline.nbm-license-init:
org.gephi.desktop.timeline.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.gephi.desktop.timeline.init:
org.gephi.desktop.timeline.up-to-date:
org.gephi.desktop.timeline.compile:
org.gephi.desktop.timeline.jar-prep:
org.gephi.desktop.timeline.jar:
org.gephi.desktop.timeline.netbeans-extra:
org.gephi.desktop.timeline.javahelp:
org.gephi.desktop.timeline.module-auto-deps:
org.gephi.desktop.timeline.release:
org.gephi.desktop.timeline.module-xml-regular:
org.gephi.desktop.timeline.module-xml-autoload:
org.gephi.desktop.timeline.module-xml-eager:
org.gephi.desktop.timeline.chmod-executables:
org.gephi.desktop.timeline.verify-class-linkage:
1 file(s) have been successfully validated.
org.gephi.desktop.timeline.netbeans:
Generating information for Auto Update...
org.netbeans.swing.dirchooser.taskdefs:
org.netbeans.swing.dirchooser.common-init:
org.netbeans.swing.dirchooser.projectized-common.basic-init:
org.netbeans.swing.dirchooser.basic-init:
org.netbeans.swing.dirchooser.files-init:
org.netbeans.swing.dirchooser.nbm-license-init:
org.netbeans.swing.dirchooser.build-init:
Scanning for modules in F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources\\platform\\platform
Scanning for modules in suite F:\\Research\\可视化\\code\\源码\\gephi-0.8.1-beta.sources
org.netbeans.swing.dirchooser.init:
org.netbeans.swing.dirchooser.up-to-date:
org.netbeans.swing.dirchooser.compile:
org.netbeans.swing.dirchooser.jar-prep:
org.netbeans.swing.dirchooser.jar:
org.netbeans.swing.dirchooser.netbeans-extra:
org.netbeans.swing.dirchooser.javahelp:
org.netbeans.swing.dirchooser.module-auto-deps:
org.netbeans.swing.dirchooser.release:
org.netbeans.swing.dirchooser.module-xml-regular:
org.netbeans.swing.dirchooser.module-xml-autoload:
org.netbeans.swing.dirchooser.module-xml-eager:
org.netbeans.swing.dirchooser.chmod-executables:
org.netbeans.swing.dirchooser.verify-class-linkage:
0 file(s) have been successfully validated.
org.netbeans.swing.dirchooser.netbeans:
Generating information for Auto Update...
run:
run.run:
至此,gephi的源码导入工作已算结束,下一步就是了解netbeans以及gephi。对于gephi有研究的请在下方留言^_^
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!如果您想持续关注我的文章,请扫描二维码,关注JackieZheng的微信公众号,我会将我的文章推送给您,并和您一起分享我日常阅读过的优质文章。
友情赞助
如果你觉得博主的文章对你那么一点小帮助,恰巧你又有想打赏博主的小冲动,那么事不宜迟,赶紧扫一扫,小额地赞助下,攒个奶粉钱,也是让博主有动力继续努力,写出更好的文章^^。
1. 支付宝 2. 微信
以上是关于可视化工具gephi源码探秘的主要内容,如果未能解决你的问题,请参考以下文章
Gephi可视化——使用Gephi Toolkit创建Gephi应用