在上篇《
可視化工具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.二、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 }
成功運行後結果以下:html
# Nodes loaded: 500
# 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:
……
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:
至此,gephi的源碼導入工做已算結束,下一步就是了解netbeans以及gephi。對於gephi有研究的請在下方留言^_^
若是您以爲閱讀本文對您有幫助,請點一下「推薦」按鈕,您的「推薦」將是我最大的寫做動力!若是您想持續關注個人文章,請掃描二維碼,關注JackieZheng的微信公衆號,我會將個人文章推送給您,並和您一塊兒分享我平常閱讀過的優質文章。java
![](http://static.javashuo.com/static/loading.gif)
友情贊助api
若是你以爲博主的文章對你那麼一點小幫助,恰巧你又有想打賞博主的小衝動,那麼事不宜遲,趕忙掃一掃,小額地贊助下,攢個奶粉錢,也是讓博主有動力繼續努力,寫出更好的文章^^。微信
1. 支付寶 2. 微信app
![](http://static.javashuo.com/static/loading.gif)