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. UIView -> image & 本地时间获取

    //UIView 转换为图片 UIGraphicsBeginImageContext(self.rootsView.bounds.size); [_rootsView.layer renderInCo ...

  2. Swift - 13 - 字符串和Character

    //: Playground - noun: a place where people can play import UIKit var str = "hi" // 字符串拼接 ...

  3. Swift - 09 - Optionals

    //: Playground - noun: a place where people can play import UIKit // swift中没有被赋值的变量是不能被使用的 //var str ...

  4. MySQL 管理

    MySQL 管理 启动及关闭 MySQL 服务器 首先,我们需要通过以下命令来检查MySQL服务器是否启动: ps -ef | grep mysqld 如果MySql已经启动,以上命令将输出mysql ...

  5. HexColorPicker 让选色变得更简单[for Mac]

    开发iOS的筒子看过来,走过路过,一不小心就错过~ Xcode里的颜色选择器,不能让你随意制定十六进制的颜色,让选色变成了一种折磨,然而作为开发者和设计师又得经常要用到. 现在有了HexColorPi ...

  6. 0627 CMD运行php代码

    打开cmd: 如何在这里面运行php代码 1.调整环境变量:右击电脑->属性->高级系统设置->环境变量 2.新建环境变量: 上部分的用户变量----- 变量名:PHP_HOME   ...

  7. django自带User管理中添加自己的字段方法

    #coding=utf-8 from django.db import models from django.contrib.auth.models import User, make_passwor ...

  8. arm的一些概念(ARM7、Cortex-M的区别)

    ARM7:ARMv4架构,ARM9:ARMv5架构,ARM11:ARMv6架构,ARM-Cortex 系列:ARMv7架构.    ARM7没有MMU(内存管理单元),只能叫做MCU(微控制器),不能 ...

  9. UVA - 524 Prime Ring Problem(dfs回溯法)

    UVA - 524 Prime Ring Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  10. RESTful API -备

    网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...