转自:http://kinganpo.iteye.com/blog/876243

import java.io.File;
/**
* 获取打包后jar的路径信息
* @author Administrator
* 2011-01-16 13:53:12
*/
public class JarTool {
//获取jar绝对路径
public static String getJarPath(){
File file = getFile();
if(file==null)return null;
return file.getAbsolutePath();
}
//获取jar目录
public static String getJarDir() {
File file = getFile();
if(file==null)return null;
return getFile().getParent();
}
//获取jar包名
public static String getJarName() {
File file = getFile();
if(file==null)return null;
return getFile().getName();
} private static File getFile() {
//关键是这行...
String path = JarTool.class.getProtectionDomain().getCodeSource()
.getLocation().getFile();
try{
path = java.net.URLDecoder.decode(path, "UTF-8");//转换处理中文及空格
}catch (java.io.UnsupportedEncodingException e){
return null;
}
return new File(path);
} }

  

获取jar包当前的路径的更多相关文章

  1. SpringBoot的配置文件加载顺序以及如何获取jar包里的资源路径

    一.读取配置文件的四种方式 这四种配置文件放置方式的读取优先级依次递减,具体可以查看官方文档. 1.1jar包同级目录下的config文件夹里的配置文件 其实我以前就见过这种方式了,只是不知道怎么做的 ...

  2. maven的介绍及如何获取jar包

    本文转载自   https://www.cnblogs.com/whgk/p/7112560.html 该篇文章篇幅较长,大概的思路如下 maven的介绍,初步认识,获取jar包的三个关键属性 --& ...

  3. 22.访问jar包下资源路径里的文件

    访问jar包下资源路径里的文件 因为打包路径和你构建的代码路径是有差异的,想要查看真实的路径情况,可以查看编译后的classes目录下的文件结构. 想要获取资源文件流: private InputSt ...

  4. 获取jar包内部的资源文件

    通常获取一个资源文件很简单,问题是对于jar包内的资源文件,可能会发生意外.假如这里有一个文件操作的类: public class FileLoader { public boolean exists ...

  5. 在swt中获取jar包中的文件 uri is not hierarchical

    uri is not hierarchical 学习了:http://blog.csdn.net/zdsdiablo/article/details/1519719 在swt中获取jar包中的文件: ...

  6. 如何获取jar包中resource下的文件

    maven工程打jar包,部署到服务器上以后,获取resource下文件的绝对路径是找不到该文件的 只能用流的方式获取,代码如下: import lombok.extern.slf4j.Slf4j; ...

  7. struts2,hibernate等模板配置文件在jar包中的路径,以及所需要的包

    一.struts2 1.struts的配置模板文件struts-default.xml的位置: struts-2.3.16.1 --> src --core --> src --> ...

  8. springboot jar启动 读取jar包中相对路径文件报错

    jar包启动后读取相对路径文件报异常: Caused by: java.io.FileNotFoundException: class path resource [***.***] cannot b ...

  9. spring+mybits 整合所需jar包的下载路径(亲测有效)

    1.spring jar包:http://repo.springsource.org/libs-release-local/org/springframework/spring/5.0.0.RELEA ...

随机推荐

  1. Memcached HA架构探索

    https://code.google.com/p/memagent/ 标签:memcached magent 高可用 HA 架构原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者 ...

  2. listen 61

    Multiple Stresses Killed Snail Memory Stress sucks. It can affect your body and mind. Previous resea ...

  3. form 提交数据编码梳理

    之前对form单提交的操作一直都是迷迷糊糊,知道怎么用,但是随着ajax2的出现,我们有更多的方式操作form表单提交,但是底层的原理我们要好好的做个梳理. 常见的form提交有post和get这两种 ...

  4. Mac替换sublime图标

    下载.icns格式一个图标:http://www.easyicon.net/language.en/iconsearch/sublime/ 终端执行:open /Applications/Sublim ...

  5. 【Lintcode】088.Lowest Common Ancestor

    题目: Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two n ...

  6. bzoj 4671 异或图 —— 容斥+斯特林反演+线性基

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4671 首先,考虑容斥,就是设 \( t[i] \) 表示至少有 \( i \) 个连通块的方 ...

  7. Cocos2d-x v3.x and Xcode 6.x with ARM 64 Architecture

    转自:http://becomingindiedev.blogspot.com.es/2014/12/cocos2d-x-v3x-and-xcode-6x-with-arm-64.html Hi! W ...

  8. java代码优化(1)---

    代码的优化,需要考虑的维度很多.但是代码的优化并不是减少代码量,有的时候我们需要增加代码来提高代码的可读性. 1.正确标记变量 2.封装某个动作 3.注意函数的写法 4.不容易理解的东西,加注释

  9. UDP 编程 客服咨询回复

    package 网络编程_客户咨询; import java.io.IOException; import java.net.DatagramPacket; import java.net.Datag ...

  10. Acdream手速赛7

    蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和 ...