首页 \ 问答 \ LoadLibrary冻结(LoadLibrary freezes)

LoadLibrary冻结(LoadLibrary freezes)

我编译了一个JNI dll,我想使用System.loadLibrary加载到我的Java应用程序中。 这在使用MSVC ++ 2008 Express编译的dll的Windows XP上完全正常。

但是,在Windows 7上,我使用MSVC ++ 2010 Express编译dll(相同的选项,相同的处理器体系结构,相同的Java版本,只是不同的操作系统和编译器),应用程序将冻结loadLibrary调用。 没有错误信息,根本没有反应。 当我在冻结过程中尝试jstack时,它也会冻结(没有输出,没有终止)。 以管理员身份运行应用程序无法解决此问题。

DLL及其所有依赖项都在java.library.path 。 事实上,当我删除它们时,Java应用程序会告诉我它们已经丢失了,所以dll必须已经正确初始化而其他方法失败了。 然而,调试证明它实际上是loadLibrary冻结,之后没有任何东西。

谁能告诉我这里会发生什么?


更新

正如我在下面的评论中所述,这个问题似乎更深入。 使用一个简单的C程序来加载所述DLL的一个依赖项已经使得冻结发生,所以这必然是Windows API的一些问题以及MSVC ++如何链接DLL(该依赖项也是由MSVC ++ 2010 Express链接的) 。


I have compiled a JNI dll that I would like to load into my Java application using System.loadLibrary. This works perfectly fine on Windows XP with the dll compiled using MSVC++ 2008 Express.

However, on Windows 7, where I compiled the dll using MSVC++ 2010 Express (same options, same processor architecture, same Java version, just different OS and compiler) the application would freeze upon the loadLibrary call. No error messages, no reaction at all. When I try jstack on the frozen process it freezes as well (no output, no termination). Running the application as an administrator does not fix this problem.

The DLL and all its dependencies are in the java.library.path. In fact, when I removed them, the Java application would tell me they're missing, so the dll must have been initialized properly and something else fails. Debugging proves, however, that it's actually loadLibrary freezing and nothing afterwards.

Can anybody tell me what might be going on here?


UPDATE:

As stated in my comment below, this problem seems to go deeper. Using a simple C program to load one of the dependencies of said DLL already makes the freeze occur, so this must be some kind of problem with the Windows API and how MSVC++ linked the DLL (that dependency was linked by MSVC++ 2010 Express as well).


原文:https://stackoverflow.com/questions/5262552
更新时间:2022-08-03 22:08

最满意答案

您应该始终通过URL重写来创建URL,不仅可以将会话信息添加到URL(如果需要),还可以添加上下文路径。 您应该从应用程序顶部创建所有URL作为绝对路径,然后让URL重写句柄,根据需要将context-path添加到前面。

<c:url value="/css/site.css"/>

如果他们没有启用cookie,那么会将/&lt;context-path&gt;/css/site.css/&lt;context-path&gt;/css/site.css;jsessionid=134345434543呈现到jsp文件中。 您还可以使用c:url标记将url呈现为​​变量,然后在整个文档中多次使用该变量。 只需在标记中添加var="x"属性,然后${x}就会将网址呈现到您的文档中。 如果您没有使用jsp来渲染输出,则需要为视图层找到适当的机制,但它们都有一个。 如果你在java代码中渲染一个url,只需看看c:url标记的源代码,你就会看到它是如何完成的。

一个尴尬是CSS文件(和js文件)没有被处理,因此css和js文件中的url需要是相对路径,否则每当你更改上下文路径时它们都会中断。 大多数js已经使用了相对路径,因为库维护者不知道你要将库安装到哪个路径。 另一方面,CSS背景图像通常被指定为绝对URL,因为相同的CSS文件可以包含在文件层次结构的不同级别的html文件中。 除了创建适当的符号链接以使相对URL始终有效或者通过JSP提供问题CSS文件以便可以适当地重写URL时,我没有简单的解决方法。 我确定你可以运行的过滤器或apache模块可以进行url替换,但是当你部署到新的上下文路径时,你仍然需要手动更新过滤器/模块。


You should always create urls via url re-writing, not only so that session info can be added to the url, if required, but also so that the context path can be added. You should create all urls as absolutely paths from the top of the application and then let url-rewriting handle adding the context-path to the front, as appropriate.

<c:url value="/css/site.css"/>

That will render /&lt;context-path&gt;/css/site.css or /&lt;context-path&gt;/css/site.css;jsessionid=134345434543 into a jsp file if they don't have cookies enabled. You can also use the c:url tag to render the url into a variable and then use that variable multiple times throughout your document. Just add a var="x" attribute to the tag and then ${x} will render the url into your doc. If you aren't using jsp to render your output, you'll need to find the appropriate mechanism for your view layer, but they will all have one. If you are rendering a url in java code, just take a look at the source code to the c:url tag and you'll see how it is done.

The one awkwardness is that CSS files (and js files) aren't processed, so urls in css and js files need to be relative paths or they will break whenever you change the context path. Most js already uses relative paths since library maintainers don't know what path you are going to install their library to. CSS backround images, on the other hand, are often specified as absolute urls, since the same CSS file may be included into html files at different levels of a file hierarchy. There is no easy fix for this that I am aware of other than to create appropriate symlinks such that the relative url always works or else serve up the problem CSS files via a JSP so that the urls can be rewritten as appropriate. I'm sure there are probably filters or apache modules you can run which will do the url replacement, but then you've still got to manually update your filter/module whenever you deploy to a new context path.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。