站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2SE 专题关于jar包的问题

关于jar包的问题

摘要: 关于jar包的问题


我想自己写一些java文件然后打包成 .jar的形式,
我以 aw/org/struts/taglib/html/ *.class 这样的路径存放.class文件,但是 在html这个包下我想放一个.properties 文件,在.class文件里怎么能读到.properties 文件的内容?
谢谢各位了



InputStream is;
File f=new File("xxx.properties");
is=new java.io.FileInputStream(f);
Properties info=new Properties();
info.load(is);


楼上但是这样的话需要文件的路径哈
只这么写 xxx.properties 不行啊
new File的时候需要的是他的完整路径阿



看这样行不:
把路径配置在配置文件中,在把配置文件中的路径给读出.


InputStream is;
String path = System.getProperty("user.dir");
File f=new File(path+"/包名/xxx.properties");
is=new java.io.FileInputStream(f);
Properties info=new Properties();
info.load(is);


String path = aplication.getRealPath("/");
File f=new File(path+"/包名/xxx.properties");
is=new java.io.FileInputStream(f);
Properties info=new Properties();
info.load(is);



我用 protected MessageResources messages = MessageResources.getMessageResources("aw.org.struts.taglib.html.LocalStrings"); 这个方法也得到了 .properties 文件中的内容呵呵
而且可以根据 messages.getMessage("common.both")得到需要的值
但不知道这么做有什么后遗症?
请大家指点一下哈
用这个是否可以?




请问一下 .properties 文件中怎么转译 {} 这两个符号哈?
谢谢le




呵呵知道 .properties 文件中的{}
是怎么回事le




InputStream is=ClassName.class.getResourseAsStream("x.properties");
Properties info=new Properties();
info.load(is);




楼上
ClassName 、class 是指什么啊?

还有就是 .properties 文件的{}之间必须是数字,怎么可以让他不是数字哈?





标记一下


在struts.jar包的
MessageResources类
public String getMessage(Locale locale, String key, Object args[])
方法中有:
JVM INSTR monitorenter 、MISSING_BLOCK_LABEL_133

这是什么意思啊




算了我把这个方法帖出来

public String getMessage(Locale locale, String key, Object args[])
{
MessageFormat format;
if(locale == null)
{
locale = defaultLocale;
}
format = null;
String formatKey = messageKey(locale, key);
HashMap hashmap = formats;
JVM INSTR monitorenter ;
String formatString;
format = (MessageFormat)formats.get(formatKey);
if(format != null)
{
break MISSING_BLOCK_LABEL_133;
}
formatString = getMessage(locale, key);
if(formatString == null)
{
return returnNull ? null : "???" + formatKey + "???";
}
format = new MessageFormat(escape(formatString));
format.setLocale(locale);
formats.put(formatKey, format);
hashmap;
JVM INSTR monitorexit ;
goto _L1
Exception exception;
exception;
throw exception;
_L1:
return format.format(((Object) (args)));
}

JVM INSTR monitorenter ;句是什么意思?
goto _L1 这个又是什么?
还有就是
JVM INSTR monitorexit ;
goto _L1
Exception exception;
exception;
throw exception;
_L1:
这段什么意思哈?




/**
* read package resource
* */
public static StringBuffer readPackageResource(String packageResource)
{
if (packageResource == null)
return null;

try
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream is = loader.getResourceAsStream(packageResource);
BufferedReader bf = new BufferedReader(new InputStreamReader(is));
StringBuffer recordBuf = new StringBuffer();
String record = null;
while ((record = bf.readLine()) != null)
{
recordBuf.append(record + "/n");
}
bf.close();
is.close();

return recordBuf;
}
catch (Exception ex)
{
Log.debug("readPackageResource(): " + ex.toString());
ex.printStackTrace();
}

return null;
}


TO xinshou1979330(Success.java):

你这个是反编译的结果吧?要研究 struts 也不用反编译呀,人家那可是开源的!


stucts不懂.
ClassName是类名
properties的{}不懂



使用 ResourceBundle 即可。


呵呵


现在是只要在properties理出现{}
这个符号就要求里面的内容一定是number型的
怎么可以回避这个问题呢?
谢谢了



好帖,收藏下!


> 现在是只要在properties理出现{}
> 这个符号就要求里面的内容一定是number型的
> 怎么可以回避这个问题呢?

用转义字符啊,写成 /u007B 试试~~


好久没有见过这个的贴了!


TO maquan('ma:kju)

在属性文件里改?

我在 properties 文件里写
第一种情况:
common.both={Basfdasfasfsdfdas} 11
然后通过common.both取提示:
javax.servlet.ServletException: javax.servlet.jsp.JspException: can't parse argument number asfdasfasfsdfdas

java.lang.IllegalArgumentException: can't parse argument number asfdasfasfsdfdas

第二种情况:
common.both=/u007Basfdasfasfsdfdas/u007B 11
或者
common.both=/u007B asfdasfasfsdfdas /u007B 11
然后通过common.both取,结果是什么也取不到了



使用 ClassLoader 中的

getResourseAsStream 方法


楼上能说得再详细点么?
谢谢先了哈



InputStream is=ExTextTag.class.getResourceAsStream("LocalStrings.properties");
Properties info=new Properties();
info.load(is);
System.out.println(info.getProperty("common.both"));
现在这么写搞定了
谢谢各位的帮忙



↑返回目录
前一篇: 希望大家发表一下看法
后一篇: 关于成员方法NATIVE?