java打印树,从树数据结构打印纯文本树(java)

I'm a huge fan of

mvn dependency:tree

and want to print a similar-looking tree as plain ascii text as output from my java program.

com.totsp.gwt:maven-gwt-sample:war:1.0-SNAPSHOT

+- com.google.gwt:gwt-servlet:jar:2.4.0:compile

+- com.google.gwt:gwt-user:jar:2.4.0:provided

| +- javax.validation:validation-api:jar:1.0.0.GA:provided

| \- javax.validation:validation-api:jar:sources:1.0.0.GA:provided

+- log4j:log4j:jar:1.2.14:compile

\- junit:junit:jar:4.1:test

I was hoping that the library that achieves this would be easily usable but I can't find it.

The closest substitute I see is this: http://code.google.com/p/j-text-utils/ but it's not as nice as Maven's.

Where can I find a library that prints a tree structure as text almost identically to mvn dependency:tree?

解决方案

I'm not an expert of creating/using MOJOs, but how about downloading and taking a look on the maven-dependency-plugin?

It's trivial to add it to your project as a dependency (I guess you're managing it by Maven), and on first sight, you should simply call TreeMojo.execute() directly or something like that.

Roughly it does something like this:

ArtifactFilter artifactFilter = createResolvingArtifactFilter();

rootNode = dependencyTreeBuilder.buildDependencyTree( project,

localRepository, artifactFactory, artifactMetadataSource,

artifactFilter, artifactCollector );

String dependencyTreeString = serializeDependencyTree( rootNode );

DependencyUtil.log( dependencyTreeString, getLog() );

Is that what you were searching for?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值