简体   繁体   English

Java SE 6和Java SE 8 JRE在Windows 7上的行为有所不同(文件权限)

[英]Java SE 6 and Java SE 8 JRE behave differently on Windows 7 (files permissions)

I have a command line Java application which reads and writes files on Windows 7 x64 platform. 我有一个命令行Java应用程序,可以在Windows 7 x64平台上读写文件。 Currently application runs with shipped IBM Java SE 6. Structure as follows: 当前,该应用程序与随附的IBM Java SE 6一起运行。结构如下:

APP_ROOT
    some_folder
    jre
        bin
        lib
    myjarfile.jar
    appl_start.bat 

Now, I replaced the jre folder with unzipped JRE 8 package. 现在,我用解压缩的JRE 8软件包替换了jre文件夹。 And the application started complaining that it can not "access" (actually it's write operation) files in some_folder. 应用程序开始抱怨它无法“访问” some_folder中的文件(实际上是写操作)。 If I create manually new some_folder_1 under APP_ROOT and re-configure application to use it - application runs just fine. 如果我在APP_ROOT下手动创建新的some_folder_1并重新配置应用程序以使用它-应用程序运行正常。 If I delete newly created some_folder_1 and rename some_folder to some_folder_1 - application complaining that it can't access it (even in read mode). 如果删除新创建的some_folder_1并将some_folder重命名为some_folder_1-应用程序抱怨它无法访问它(即使在读取模式下)。

If I replace jre folder with JRE 6 files - application start working fine. 如果我用JRE 6文件替换jre文件夹-应用程序开始正常运行。

Tried comparing effective permissions via Properties - all looks the same, nothing suspicious. 尝试通过“属性”比较有效权限-看起来都一样,没有可疑之处。 UAC is turned on, I'm working and doing folders replacement under regular user. UAC已打开,我正在根据常规用户进行文件夹替换。

UPDATE : After I turned off UAC in Windows 7 and rebooted, application started working fine with JRE 8. But I need to make it working with UAC turned on. 更新 :在Windows 7中关闭UAC并重新启动后,应用程序可以在JRE 8上正常运行。但是我需要使其与UAC一起打开。 When reverted UAC to on and rebooted - application with JRE 8 failed again. 将UAC恢复为开启状态并重新启动后-具有JRE 8的应用程序再次失败。 Also, noticed that seems JRE 8 does not create properly files in "C:\\Users\\username\\AppData\\Local\\VirtualStore\\Program Files (x86)\\", where it normally create when program attempts to write inside Program Files. 此外,请注意,似乎JRE 8不能在“ C:\\ Users \\ username \\ AppData \\ Local \\ VirtualStore \\ Program Files(x86)\\”中正确创建文件,通常在程序尝试在Program Files中写入时在该位置创建。

UPDATE 2 : Did more troubleshooting, and narrowed problem: 更新2 :进行了更多的故障排除和缩小的问题:

  1. Application with JRE 8 fails only when it writes to "C:\\Program Files\\APP_ROOT\\some_folder" 仅当JRE 8的应用程序写入“ C:\\ Program Files \\ APP_ROOT \\ some_folder”时,它才会失败
  2. By Windows 7 design in this case file expected to be created in C:\\User..\\VirtualStore, but JRE 8 can not do this ( which is wrong and the root of the problem ) 通过Windows 7设计,在这种情况下,预期在C:\\ User .. \\ VirtualStore中创建文件,但是JRE 8无法做到这一点( 这是错误的,也是问题的根源
  3. JRE 6 can create files fine in VirtualStore. JRE 6可以在VirtualStore中很好地创建文件。
  4. VirtualStore content was cleaned up before re-run with JRE 8 在使用JRE 8重新运行之前,已清理VirtualStore内容
  5. The succeeded run with "some_folder_1" and JRE 8 combination was because JRE 8 actually wrote inside C:\\Program Files/APP_ROOT/some_folder_1 - which is violation IMHO. 成功运行“ some_folder_1”和JRE 8组合是因为JRE 8实际上是在C:\\ Program Files / APP_ROOT / some_folder_1内编写的,这违反了恕我直言。 So, this is another problem - why JRE 8 did not redirect writing to filesystem in the VirtualStore, and modified instead C:\\Program Files subfolder. 因此,这是另一个问题-为什么JRE 8没有将写入重定向到VirtualStore中的文件系统,而是修改了C:\\ Program Files子文件夹。
  6. If I define %localusrdir% to some C:\\temp directory, JRE 8 shows the same problem, so it's not only specific problem of VirtualStore folder, IMHO. 如果我在某些C:\\ temp目录中定义%localusrdir%,则JRE 8会显示相同的问题,因此,这不仅是VirtualStore文件夹IMHO的特定问题。

So, I make conclusion - for some reason JRE 8 can not redirect writing output to C:\\Program Files... into C:\\Users...\\VirtualStore 因此,我得出一个结论- 出于某种原因,JRE 8无法将写入输出到C:\\ Program Files ...重定向到C:\\ Users ... \\ VirtualStore

How it can be fixed, so JRE 8 start writing in VirtualStore fine as JRE 6 does? 如何修复它,以便JRE 8像JRE 6一样开始在VirtualStore中编写?

UPDATE 3 : the failing JRE version: 更新3 :失败的JRE版本:

C:\Program Files (x86)\APP\jre\bin>java.exe -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build pwi3280-20150129_02)
IBM J9 VM (build 2.8, JRE 1.8.0 Windows 7 x86-32 20150116_231420 (JIT enabled, AOT enabled)
J9VM - R28_Java8_GA_20150116_2030_B231420
JIT  - tr.r14.java_20150109_82886.02
GC   - R28_Java8_GA_20150116_2030_B231420
J9CL - 20150116_231420)
JCL - 20150123_01 based on Oracle jdk8u31-b12

You don't. 你不知道 JRE 8 is probably telling Windows not to redirect and I'd imagine that's not something you can change. JRE 8可能告诉Windows不要重定向,并且我想这不是您可以更改的东西。 (By the way, automatically redirecting to VirtualStore is a Windows feature, not a Java one.) (顺便说一句,自动重定向到VirtualStore是Windows的功能,而不是Java的功能。)

VirtualStore is meant for old and misbehaving programs -- not for new ones. VirtualStore适用于旧的和行为不佳的程序-不适用于新程序。 You should be storing your data where user/application data is meant to go , and in this case it would be in AppData. 您应该将数据存储在用户/应用程序数据应该到达的地方 ,在这种情况下,它将存储在AppData中。 If you have existing data (eg this is an upgrade from an old program) then you should migrate the data from that location to a new one that the user can write to. 如果您已有数据(例如,这是旧程序的升级),则应将数据从该位置迁移到用户可以写入的新位置。

If you need multiple users to be able to write to the same files then you may have to modify the ACLs / file permissions so that those other users can write to the same files -- this shouldn't require admin rights. 如果您需要多个用户才能写入相同的文件,则可能必须修改ACL /文件权限,以便其他用户可以写入相同的文件-这不需要管理员权限。

Alternatively, the user could take ownership of / add write permissions to the APP_ROOT but that would require admin rights. 或者,用户可以拥有APP_ROOT的所有权/向其添加写权限,但这需要管理员权限。

Finally, if you really want to still use VirtualStore, then you can probably detect the JRE version (or make an read/write attempt and catch the exception) and use the VirtualStore path directly, which is likely something you can write to normally if so desired. 最后,如果您确实仍然想使用VirtualStore,则可以检测到JRE版本(或进行读/写尝试并捕获异常),然后直接使用VirtualStore路径,如果这样的话,您可能可以正常写这些东西想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM