eclipse通过classpath variable引用类库

http://jazgung.iteye.com/blog/743691

 

http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fbuildpath%2Fref-preferences-classpath-variables.htm

Classpath variables can be used in a Java Build Path to avoid a reference to the local file system. Using a variable entry, the classpath only contains a variable and the build path can be shared in a team. The value of such variables is configured on the  Java > Build Path > Classpath Variables preference page.

 

 

众所周知,eclipse的project bulid path中可以引用第三方类库(如图1),

图1

图1

但是这种方式有个缺点:对类库的引用是通过绝对路径。如果有两台电脑(办公室1台、家1台),很可能造成因为类库的路径不同导致eclipse报错。

但事实上,两台电脑中只是libraries目录的绝对路径不同,从libraries开始的子目录完全同步。

只要满足这个条件,就可以用下面的方式引入类库:

1.建立classpath variable。在window->preferences中的建立新的classpath variable(如图2);

图2

图2

2.在build path中选择add varibale,然后在弹出的窗口中选择变量项并选择extend...(如图3)

图3

图3

3.在variable extend窗口中选择所需要的类库(如图4)

图4

图4

这样,类库就是以基于classpath variable的相对路径引用(如图5),

图5

图5

只要能保证两台电脑上所有类库从某一目录开始的相对路径一致,就可以通过建立eclipse的classpath variable保证项目在两台电脑迁移的过程中不会因为引用类库而报错。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值