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:

  1. 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.xml should just work fine.
  2. /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.
  3. 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的更多相关文章

  1. Could not write file: C:\......\.classpath

    最近因为换操作系统,把项目从Mac系统copy到了win10下,出现了不少项目部署启动上的问题.最开始的一个问题是:Could not write file: C:\......\.classpath ...

  2. 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 ...

  3. /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 ...

  4. 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 ...

  5. 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 ...

  6. version GLIBCXX3.4.21 not defined in file libstdc++.so.6 with link time reference

    问题:在运行C++程序时,输入 ./a.out 输出:symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev, version ...

  7. 【转】Could not write file XXX\.classpath解决

    原文网址:http://www.sjsjw.com/kf_other/article/323_11877_12218.asp 环境 MyEclipse 8.6 + Windows 7 Ultimate ...

  8. 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也 ...

  9. 极路由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 ...

随机推荐

  1. 使用top工具,找出消耗CPU 较多的进程

    1.使用top工具,找出消耗CPU 较多的进程 [oracle@cuug ~]$ top top - 10:48:27 up 23:15,  4 users,  load average: 1.09, ...

  2. 关于Core Data的一些整理(三)

    关于Core Data的一些整理(三) 关于Core Data Stack的四种类与它们的关系如下: NSManagedObjectModel NSPersistentStore NSPersiste ...

  3. centos node卸载

    1.通过包管理工具 如果是通过包管理工具安装的话,那就和包管理工具卸载 yum remove nodejs npm -y 2.手动 如果是通过手动安装:官方下载后安装 进入到安装的路径 cd /opt ...

  4. iOS开发,新手入门指导

    在做了近两年wp,安卓开发之后,某一天突然决定投身iOS的开发之中. 因为一直用的mac,做wp开发的时候都用双系统,vs开久了,就会比较烫,这点让人不爽.后来更多地做安卓,直接mac下开发,很舒适的 ...

  5. 页面添加 mask 遮罩层

    var mask = function(){ $('<div>').css({ position: 'fixed', left: 0, top: 0, width: '100%', hei ...

  6. JQUERY1.9学习笔记 之内容过滤器(二) 空元素选择器

    描述:选择没有子元素(包括文本节点)的标签. jQuery(":empty") 与:parent相反. 例:找出所有为空的元素.(他们没有子元素或文本元素). <!docty ...

  7. php开发中的url地址传输加密解密函数

    function keyED($txt,$encrypt_key) //定义一个keyED { $encrypt_key = md5($encrypt_key); $ctr=0; $tmp = ''; ...

  8. python3数据类型--数字

    数字 Python数字数据类型用于存储数值.数字数据类型是不允许改变的,所以如果改变数字数据类型的值,将重新分配内存空间. 以下实例在变量赋值时Number对象被创建: #!/usr/bin/env ...

  9. 浅谈Android序列化

    序列化原因 序列化的原因基本可以归纳为以下三种情况: 永久性保存对象,保存对象的字节序列到本地文件中: 对象在网络中传递: 对象在IPC间传递. --- --- 序列化方法 在Android系统中关于 ...

  10. Hybrid----优秀开源代码解读之JS与iOS Native Code互调的优雅实现方案-备

    本篇为大家介绍一个优秀的开源小项目:WebViewJavascriptBridge. 它优雅地实现了在使用UIWebView时JS与ios 的ObjC nativecode之间的互调,支持消息发送.接 ...