我有一個程序配置爲使用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
感謝您的suggenstion的問題!但是,這會導致編譯版本和IDE中出現相同的前提錯誤。 –