{"id":250,"date":"2018-03-26T21:43:50","date_gmt":"2018-03-26T12:43:50","guid":{"rendered":"http:\/\/ito-u-oti.com\/?p=250"},"modified":"2018-05-06T12:25:05","modified_gmt":"2018-05-06T03:25:05","slug":"post-250","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=250","title":{"rendered":"spring\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u3066\u3001jar\u306e\u4e2d\u306b\u3042\u308bxml\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3046\u8a2d\u5b9a FileNotFoundException"},"content":{"rendered":"<h2 id=\"outline__1\">spring\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u3066\u3001jar\u306e\u4e2d\u306b\u3042\u308bxml\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3046\u8a2d\u5b9a FileNotFoundException<\/h2>\n<h3 id=\"outline__1_1\">jar\u81ea\u8eab\u304cjar\u306e\u4e2d\u306b\u3042\u308bxml\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3046\u8a2d\u5b9a FileNotFoundException<\/h3>\n<p>\u3069\u3046\u3044\u3046\u3053\u3068\u304b\u30fb\u30fb\u30fb<br \/>\n\u56f3\u3067\u89e3\u8aac<br \/>\n<img decoding=\"async\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2018\/03\/xml\u547c\u3073\u51fa\u3057-1024x1015.png\" alt=\"\" width=\"1024\" height=\"1015\" class=\"alignnone size-large wp-image-251\" \/><br \/>\nhoge.project\u5185\u306ehoge.java\u306e\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u3001resources\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u3042\u308bpoge.xml\u3092\u8aad\u307f\u8fbc\u307e\u305b\u305f\u3044\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>IDE\u4e0a\u3067\u306f\u5b9f\u969b\u306b\u3053\u3046\u3044\u3046\u51e6\u7406\u3092\u66f8\u304d\u307e\u3057\u305f\u3002<br \/>\n\uff08Xml\u306b\u306f\u300cpoge.xml\u300d\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic InputStream inputLayoutXml(String Xml) throws IOException {\r\n    \r\n    Resource resource = resourceLoader.getResource(&quot;classpath:&quot; + Xml);\r\n    File xmlFile = resource.getFile();\r\n    InputStream fileStream = new FileInputStream(xmlFile);\r\n    \r\n    return fileStream;\r\n}\r\n<\/pre>\n<p>resources\u914d\u4e0b\u3092\u8aad\u307f\u8fbc\u3081\u308b\u3088\u3046\u306b\u30af\u30e9\u30b9\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u3001poge.xml\u3092\u76f8\u5bfe\u6307\u5b9a\u3067\u8a2d\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n<a href=\"http:\/\/javatechnology.net\/spring\/servlet-context-classpath-file\/\">classpath\u306b\u3064\u3044\u3066\u306e\u5206\u304b\u308a\u3084\u3059\u3044\u8aac\u660e\u306f\u3053\u3061\u3089\u3067<\/a><\/p>\n<p>\u5b9f\u969b\u306bIDE\u4e0a\u3067\u306f\u6b63\u5e38\u306b\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u4e0a\u624b\u304f\u3044\u3063\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3057\u30d3\u30eb\u30c9\u3057\u3066jar\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3002jar\u304b\u3089\u306e\u8d77\u52d5\u3092\u8a66\u307f\u307e\u3057\u305f\u3002<br \/>\n\u3059\u308b\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\njava.io.FileNotFoundException: class path resource &#x5B;\/poge.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:\/C:\/hoge.jar!\/poge.xml\r\n        at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:218)\r\n        at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)\r\n        at sharedservice.InputFileImpl.inputLayoutXml(InputFileImpl.java:31)\r\n        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\r\n        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\r\n        at java.lang.reflect.Method.invoke(Unknown Source)\r\n        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)\r\n        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)\r\n        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)\r\n        at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)\r\n        at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)\r\n        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)\r\n        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)\r\n        at com.sun.proxy.$Proxy25.execute(Unknown Source)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)\r\n        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)\r\n        at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)\r\n        at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)\r\n        at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)\r\n        at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)\r\n        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)\r\n        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)\r\n        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)\r\n        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)\r\n        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)\r\n        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)\r\n        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)\r\n        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)\r\n        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)\r\n        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)\r\n        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)\r\n        at org.springframework.batch.core.launch.support.SimpleJobOperator.start(SimpleJobOperator.java:314)\r\n        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\r\n        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\r\n        at java.lang.Thread.run(Unknown Source)\r\n<\/pre>\n<p>jar\u306e\u4e2d\u306b\u3042\u308bxml\u3092\u4e0a\u624b\u304f\u8aad\u307f\u8fbc\u3093\u3067\u304f\u308c\u3066\u3044\u306a\u3044\u3002<br \/>\n\u30b0\u30b0\u3063\u3066\u307f\u308b\u3068\u3044\u304f\u3064\u304b\u30d2\u30c3\u30c8\u3002<br \/>\n\u300c\u30ea\u30bd\u30fc\u30b9\u304c\u30d5\u30a1\u30a4\u30eb\u3067\u3042\u308b\u3068\u4eee\u5b9a\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u4f7f\u7528\u3057\u3066\u8aad\u307f\u53d6\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u30b0\u30fc\u30b0\u30eb\u7ffb\u8a33\u8ac7\uff09\u300d<br \/>\n<a href=\"https:\/\/github.com\/spring-projects\/spring-boot\/issues\/10983\">\u53c2\u8003\uff11<\/a><br \/>\n<a href=\"https:\/\/coderanch.com\/t\/474047\/frameworks\/Spring-find-file-classpath-JAR\">\u53c2\u8003\uff12<\/a><\/p>\n<p>\u6700\u7d42\u7684\u306b\u306f\u8a66\u3057\u3066\u3044\u304f\u3057\u304b\u306a\u3044\u3068\u601d\u3044\u3001system.out\u3067\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u8aad\u307f\u53d6\u308c\u308b\u304b\u8a66\u3057\u3066\u3044\u3063\u305f\u3002<\/p>\n<h3 id=\"outline__1_2\">\u305d\u306e\uff11<\/h3>\n<p>ResourceLoader\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Service\r\npublic class InputFileImpl implements InputFile {\r\n\r\n    @Inject\r\n    ResourceLoader resourceLoader;\r\n\r\n    @Override\r\n    public InputStream inputLayoutXml(String Xml) throws IOException {\r\n\r\n        System.out.println(Xml);\r\n        System.out.println(resourceLoader.getResource(&quot;classpath:&quot; + Xml).getURL().getFile());\r\n        \r\n        File xmlFile = new File(resourceLoader.getResource(&quot;classpath:&quot; + Xml).getURL().getFile());\r\n        InputStream fileStream = new FileInputStream(xmlFile);\r\n        return fileStream;\r\n    }\r\n}\r\n<\/pre>\n<p>\u7d50\u679c<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\npoge.xml\r\nfile:\/C:\/hoge.jar!\/poge.xml\r\njava.io.FileNotFoundException: file:\\C:\\hoge.jar!\\poge.xml (\u30d5\u30a1\u30a4\u30eb\u540d\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3001\u307e\u305f\u306f\u30dc\u30ea\u30e5\u30fc\u30e0 \u30e9\u30d9\u30eb\u306e\u69cb\u6587\u304c\u9593\u9055\u3063\u3066\u3044\r\n        at java.io.FileInputStream.open0(Native Method)\r\n        at java.io.FileInputStream.open(Unknown Source)\r\n        at java.io.FileInputStream.&lt;init&gt;(Unknown Source)\r\n        at InputFileImpl.inputLayoutXml(InputFileImpl.java:39)\r\n        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\r\n        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\r\n        at java.lang.reflect.Method.invoke(Unknown Source)\r\n        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)\r\n        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)\r\n        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)\r\n        at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)\r\n        at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)\r\n        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)\r\n        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)\r\n        at com.sun.proxy.$Proxy24.execute(Unknown Source)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)\r\n        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)\r\n        at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)\r\n        at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)\r\n        at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)\r\n        at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)\r\n        at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)\r\n        at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)\r\n        at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)\r\n        at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)\r\n        at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)\r\n        at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)\r\n        at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)\r\n        at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)\r\n        at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)\r\n        at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)\r\n        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)\r\n        at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)\r\n        at org.springframework.batch.core.launch.support.SimpleJobOperator.start(SimpleJobOperator.java:314)\r\n        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\r\n        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\r\n        at java.lang.Thread.run(Unknown Source)\r\n<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u306f\u8aad\u307f\u8fbc\u3081\u3066\u3044\u308b\u304c\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3002<br \/>\n\u3088\u304f\u898b\u308b\u3068\u3001\u300cfile:\\C:\\hoge.jar!\\poge.xml\u300d\u3063\u3066\u66f8\u3044\u3066\u3042\u308b\u306e\u3067jar\u306e\u5916\u5074\u306e\u540c\u3058\u540d\u524d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306bxml\u30d5\u30a1\u30a4\u30eb\u3092\u547c\u3073\u306b\u884c\u3063\u3066\u308b\u3063\u307d\u3044\u3002<br \/>\n\u305d\u308a\u3083jar\u306e\u4e2d\u306b\u3042\u308b\u3093\u3060\u304b\u3089\u5916\u898b\u3066\u3082\u306a\u3044\u308f\u3051\u3067\u3059\u3088\u3002<\/p>\n<h3 id=\"outline__1_3\">\u305d\u306e\uff12<\/h3>\n<p>URL\u30af\u30e9\u30b9\u306b\u683c\u7d0d\u3057\u3066\u547c\u3073\u51fa\u3057<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Service\r\npublic class InputFileImpl implements InputFile {\r\n\r\n    @Inject\r\n    ResourceLoader resourceLoader;\r\n\r\n    @Override\r\n    public InputStream inputLayoutXml(String Xml) throws IOException {\r\n\r\n        System.out.println(Xml);\r\n        \r\n        URL url = resourceLoader.getResource(&quot;classpath:&quot; + Xml).getURL();\r\n        System.out.println(url);\r\n        \r\n        InputStream fileStream = url.openStream();\r\n        return fileStream;\r\n    }\r\n}\r\n<\/pre>\n<p>\u7d50\u679c<\/p>\n<p>\u7121\u4e8bjar\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u306exml\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u306b\u6210\u529f\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>spring\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u3066\u3001jar\u306e\u4e2d\u306b\u3042\u308bxml\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3046\u8a2d\u5b9a FileNotFo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":93,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,7],"tags":[92,94,93,10],"class_list":["post-250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring","category-error-bugs","tag-classpath","tag-filenotfoundexception","tag-jar","tag-spring"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":4,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions\/469"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/93"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}