how to get file from classpath using jboss7.x.1 --reference
question:
I want to convert smooks xml-java, so that i need to load source file from mobeeadmin.war/WEB-INF/sample.xml.
Smooks smooks = new Smooks("/WEB-INF/sample.xml");
It is throwing following exception:
java.io.IOException: Failed to access data stream for resource [/WEB-INF/sample.xml]. Tried (in order):
10:10:14,113 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) File System: E:\WEB-INF\sample.xml
10:10:14,114 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) File System: E:\jboss-as-7.1.1.Final\bin\WEB-INF\sample.xml
10:10:14,117 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) Classpath: /WEB-INF/sample.xml
10:10:14,125 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) By default it looks in File System: E:\jboss-as-7.1.1.Final\bin\WEB-INF\sample.xml .I want load from E:\jboss-as-7.1.1.Final\standalone\deployments\myproject.war\WEB-INF\sample.xml.
answer:
- What Smooks takes as a String is a file name. If you take a relative one it's interpreted relative to the start location of your java application. But of course you could take an absolute one too. So
E:/data/sample.xmlshould just work fine. - /WEB-INF/sample.xml can't be on the classpath, as WEB-INF then would be a package name. But those must not contain dashes. In fact it's a resource file of your web application and you can get a stream to load it by
ServletContext.getResourceAsStream(java.lang.String path). As JBoss7 is Servlet 3.0 compilant you can get the ServletContext from the HttpServletRequest. However some modern Frameworks give you neither. If you'd like to get your file from the class path you could move it to WEB-INF/classes and load it via a classloader. However, java is pretty picky with the right one. Most reliable is the ContextClassloader (it's now in the root package):
Thread.currentThread().getContextClassLoader().getResourceAsStream("sample.xml");
reference from:http://stackoverflow.com/questions/15633371/how-to-get-file-from-classpath-using-jboss7-x-1
how to get file from classpath using jboss7.x.1 --reference的更多相关文章
- Could not write file: C:\......\.classpath
最近因为换操作系统,把项目从Mac系统copy到了win10下,出现了不少项目部署启动上的问题.最开始的一个问题是:Could not write file: C:\......\.classpath ...
- error: /lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference
]$ sudo yum install libnotify*Loaded plugins: fastestmirror, refresh-packagekit, securitySetting up ...
- /usr/lib64/python2.6/lib-dynload/pyexpat.so: symbol XML_SetHashSalt, version EXPAT_2_0_1_RH not defined in file libexpat.so.1 with link time reference
解决方法:[root]$cd /usr/lib64/python2.6/lib-dynload[root]$ln -s /lib64/libexpat.so.1.5.2 libexpat.so.0[r ...
- Docker异常:/lib/x86_64-linux-gnu/libnss_files.so.2: symbol __libc_readline_unlocked, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference
当使用docker cp 将容器内数据拷贝至主机时,或是使用docker export 命令归档容器文件时,出现下述异常: Error response from daemon: error proc ...
- version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference
在python中运行如下: $ python >>> import wx 输出:symbol _ZNSt7__cxx1112basic_stringIwSt11char_traits ...
- version GLIBCXX3.4.21 not defined in file libstdc++.so.6 with link time reference
问题:在运行C++程序时,输入 ./a.out 输出:symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev, version ...
- 【转】Could not write file XXX\.classpath解决
原文网址:http://www.sjsjw.com/kf_other/article/323_11877_12218.asp 环境 MyEclipse 8.6 + Windows 7 Ultimate ...
- relocation error: /usr/lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference 问题解决
在建立一个错误的软连接到ld-linux-x86-64.so.2时,悲剧就这么发生了.此时大部分命令都不能使用,SSH当然也不能登录了.这个时候一定不要退出终端. 有人说那就把软连接复原吧,可是ln也 ...
- 极路由4pro安装java(Jamvm 2.0.0 + gnu classpath 0.9.8)
首先试了gnu classpath 0.9.9,编译不过后来改成0.9.8 编译环境 OS: 64位 Ubuntu 16.04 LTS(vmware虚拟机) SDK: 用之前讲过的官方SDKmtmip ...
随机推荐
- Linux服务器指令
1.查看cpu信息:/proc/cpuinfo2.查看内存信息:/prco/meminfo3.查看服务器版本信息:cat /etc/issue4.服务器系统位数:uname -a5.网卡信息:ifco ...
- _Obj* __STL_VOLATILE* __my_free_list
今天在读<STL源码剖析>空间配置器第二级时看到了这句,有点不解,于是查阅后知: obj后面是个指针 STL_VOLATILE也应该是个类型定义的吧,程序中应该有define来对它定义.所 ...
- 利用js加载本地图片预览功能
直接上代码: 经测试,除safari6包括6以下不支持,其他均可正常显示. 原因:safari6不支持filereader,同时不能使用IE滤镜导致失效. fix: 可以利用canvas,解决safa ...
- C++普通函数与模板函数以及特化函数重载的优先级问题
在面对C++模板的时候,需要十分注意,因为模板的复杂性有很多情况,所以最好学习模板的方法我个人认为就是用到就去学,用不到就尽量别去看各种奇门怪技,因为你就算看了,好不容易搞懂模板的实现内部了,包括元编 ...
- webAPP前端必备知识
了解各浏览器内核 Firefox:-moz-box-shadow Safari:-webkit-box-shadow Opera:-o-box-shadow IE:-ms-box-shadow Web ...
- js学习笔记之:键盘应用
为了方便用户操作,可以为用户设置(或者屏蔽)功能键,代替使用频率比较高的操作.本次,将学习一下基本的功能键使用方法.键盘和焦点使用.屏蔽按键等知识点,以及一些相关示例: 1 设置按键功能: 功能键主要 ...
- 利用Php ssh2扩展实现svn自动提交到测试服务器
1.安装ssh2扩展 (1)window . 下载 php extension ssh2 下载地址 http://windows.php.net/downloads/pecl/releases/ssh ...
- beini系列_1_U盘引导制作
奶瓶(beini)这个系统,是一款基于 Tiny Core Linux 搭建的无线网络安全测试系统,当然由于它是用来安全测试的系统,因此在安全方面自然有着强大的功能.而且,这个系统非常简便易学,因此现 ...
- Windows平台下主要的内存管理途径
new / delete malloc / free CoTaskMemAlloc / CoTaskMemFree IMalloc::alloc / IMalloc/free G ...
- Tomcat内存溢出详解【转载】
本文转载自 http://elf8848.iteye.com/blog/378805 Java内存溢出详解 一.常见的Java内存溢出有以下三种: 1. java.lang.OutOfMemoryEr ...