2015-11-14 39 views
0

我有一个程序配置为使用Apache Shiro ini文件来存储其用户和权限。无法找到可执行文件夹的根目录中的资源

下面的代码工作在IDE

代码

public static String loginModule(String heelName, String heelPass) { 

     Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); 
     SecurityManager securityManager = factory.getInstance(); 

     SecurityUtils.setSecurityManager(securityManager); 

     Subject usr = SecurityUtils.getSubject(); 
     UsernamePasswordToken token = new UsernamePasswordToken(heelName, heelPass); 


     try { 
      usr.login(token); 
     } catch (AuthenticationException ae) { 
      return ae.toString(); 
     } 

但与Maven的JavaFX插件编译,程序无法找到其CLASSPATH中shiro.ini文件。时,会产生以下错误:

错误

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further detail 
s. 
Exception in thread "JavaFX Application Thread" org.apache.shiro.config.Configur 
ationException: java.io.IOException: Resource [classpath:shiro.ini] could not be 
found. 
     at org.apache.shiro.config.Ini.loadFromPath(Ini.java:242) 
     at org.apache.shiro.config.Ini.fromResourcePath(Ini.java:225) 
     at org.apache.shiro.config.IniSecurityManagerFactory.<init>(IniSecurityM 
anagerFactory.java:69) 
     at Login.loginModule(Login.java:23) 
     at LoginController.attemptToLoginbutton(LoginController.java:178) 
     at LoginController$1.handle(LoginController.java:98) 
     at LoginController$1.handle(LoginController.java:96) 
     at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Comp 
ositeEventHandler.java:86) 
     at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH 
andlerManager.java:238) 
     at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH 
andlerManager.java:191) 
     at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(C 
ompositeEventDispatcher.java:59) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:58) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
     at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) 
     at javafx.event.Event.fireEvent(Event.java:198) 
     at javafx.scene.Node.fireEvent(Node.java:8411) 
     at javafx.scene.control.Button.fire(Button.java:185) 
     at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Bu 
ttonBehavior.java:182) 
     at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorS 
kinBase.java:96) 
     at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorS 
kinBase.java:89) 
     at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.h 
andleBubblingEvent(CompositeEventHandler.java:218) 
     at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Comp 
ositeEventHandler.java:80) 
     at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH 
andlerManager.java:238) 
     at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventH 
andlerManager.java:191) 
     at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(C 
ompositeEventDispatcher.java:59) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:58) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDis 
patcher.java:56) 
     at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispat 
chChainImpl.java:114) 
     at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
     at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) 
     at javafx.event.Event.fireEvent(Event.java:198) 
     at javafx.scene.Scene$MouseHandler.process(Scene.java:3757) 
     at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) 
     at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) 
     at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) 
     at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotificatio 
n.run(GlassViewEventHandler.java:352) 
     at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotificatio 
n.run(GlassViewEventHandler.java:275) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEve 
nt$355(GlassViewEventHandler.java:388) 
     at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Quantum 
Toolkit.java:389) 
     at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Glas 
sViewEventHandler.java:387) 
     at com.sun.glass.ui.View.handleMouseEvent(View.java:555) 
     at com.sun.glass.ui.View.notifyMouse(View.java:937) 
     at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
     at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.ja 
va:191) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: java.io.IOException: Resource [classpath:shiro.ini] could not be foun 
d. 
     at org.apache.shiro.io.ResourceUtils.getInputStreamForPath(ResourceUtils 
.java:139) 
     at org.apache.shiro.config.Ini.loadFromPath(Ini.java:240) 
     ... 61 more 

由于这是一个行家项目,看着该项目的源代码时,INI位于/ SRC /主/资源文件夹中。

我已验证shiro.ini文件实际上存在于可执行jar的根目录中。有关如何克服这个错误的任何建议?

潜在资源

https://shiro.apache.org/static/1.2.1/apidocs/org/apache/shiro/config/IniSecurityManagerFactory.html

http://shiro.apache.org/configuration.html

回答

0

我建议尝试:的

new IniSecurityManagerFactory("classpath:/shiro.ini"); 

代替:

new IniSecurityManagerFactory("classpath:shiro.ini"); 
+0

感谢您的suggenstion的问题!但是,这会导致编译版本和IDE中出现相同的前提错误。 –

0

IDE比编译的程序更宽容。当给出“shiro.ini”时,它仍然能够找到“Shiro.ini”,但编译后的程序要求修正该大小写错误。

new IniSecurityManagerFactory("classpath:shiro.ini"); 

更正为:

new IniSecurityManagerFactory("classpath:Shiro.ini"); 

整流

相关问题