我正在使用aQute Bnd工具集来创建一个OSGi包,并打包了一些相关的"资源"文件.这包括我创建的资源目录中的*.css文件和*.xsd文件.
我在bundle.bnd文件中包含以下内容:
Include-Resource: resources/=resources/
Run Code Online (Sandbox Code Playgroud)
当我进行构建时,生成的*.jar文件在jar包文件的顶级目录的resources目录中包含*.css和*.xsd文件.
但是,在实际代码中,我很难尝试将其作为类路径的一部分引用:
我尝试过以下方法:
new File("resources/example.css");
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
URL cssFile = this.getClass().getResource("resources/example.css");
try
{
file = new File(cssFile.toURI()));
}
catch(Exception e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我得到一个NullPointException错误或无法找到文件IOException错误(取决于我使用哪一个).我在调试配置模式下运行Eclipse Equinox以及Apache Felix(我们用于部署)时遇到此错误.注意我试图在BundleActivator之外的Java类中执行此操作.
我是否需要始终参考BundleActivator的上下文,例如?
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception
{
/* Service to host the Bundle interface. */
ServletContainerService service = new ServletContainerService();
service.addServlet(new ServletContainer(new AxisServlet(), true));
this.serverReg = context.registerService(ServletContainerService.class.getName(), service, null);
cssFile = new File(context.getClass.getResource("resource/example.css"));
}
Run Code Online (Sandbox Code Playgroud)
我认为上面的内容会起作用,但意味着我将不得不传递cssFile参考,而这个参考似乎并不优雅.
有没有办法在bundle/.jar文件的任何给定Java类中引用bundle jar文件中包含的'resources'目录的路径?如果它涉及BundleContext,有没有办法在任何Java类中引用它?
任何帮助都感激不尽.
我已经看过并 …
我收到以下错误:
回溯(最近一次调用最后一次):
在test_single_search中输入"../tests.py",第92行对于serializers.deserialize中的return_obj("json",response,ensure_ascii = False):
文件"/Library/Python/2.6/site-packages/django/core/serializers/json.py",第38行,在反序列化器中为obj in PythonDeserializer(simplejson.load(流),**选项):文件"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/json/ INIT py"为,线264,在负荷返回load(fp.read(),AttributeError:'HttpResponse'对象没有属性'read'
在views.py中,序列化正常工作:
resultsjson = serializers.serialize("json", results, ensure_ascii=False)
return HttpResponse(resultsjson, mimetype = 'application/json')
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在test.py中的调用方法中处理结果时:
response = self.client.get("/path/?query=testValue")
for return_obj in serializers.deserialize("json", response, ensure_ascii=False):
print return_obj
Run Code Online (Sandbox Code Playgroud)
我得到了上述错误.有没有人遇到同样的错误.我正在使用Django 1.2(来自svn的最新版本),它似乎使用内置的simplejson序列化器.