Where does ClassLoader.getSystemResource() go to? - java

There is existing code that has a call
URL resource = ClassLoader.getSystemResource("hp.obo.gz");
From my understanding, this searches the classpath for the requested file. I printed out the classpath using the code from here: https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/
and got the following:
/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.3/lib/idea_rt.jar
/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.3/plugins/junit/lib/junit-rt.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/charsets.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/deploy.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/access-bridge-64.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/cldrdata.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/dnsns.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/jaccess.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/jfxrt.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/localedata.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/nashorn.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunec.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunjce_provider.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunmscapi.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunpkcs11.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/zipfs.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/javaws.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jce.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jfr.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jfxswt.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jsse.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/management-agent.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/plugin.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/resources.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/rt.jar
/C:/Users/johnp/Desktop/git_stuff/boqa/target/test-classes/
/C:/Users/johnp/Desktop/git_stuff/boqa/target/classes/
/C:/Users/johnp/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
/C:/Users/johnp/.m2/repository/de/charite/compbio/ontologizer-core/2.1-SNAPSHOT/ontologizer-core-2.1-20160115.222100-6.jar
/C:/Users/johnp/.m2/repository/com/att/research/grappa/1.2.1/grappa-1.2.1.jar
/C:/Users/johnp/.m2/repository/de/charite/compbio/ontologizer-benchmark/2.1-SNAPSHOT/ontologizer-benchmark-2.1-20160115.222106-6.jar
/C:/Users/johnp/.m2/repository/com/beust/jcommander/1.35/jcommander-1.35.jar
/C:/Users/johnp/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar
/C:/Users/johnp/.m2/repository/org/apache/logging/log4j/log4j-1.2-api/2.8.2/log4j-1.2-api-2.8.2.jar
/C:/Users/johnp/.m2/repository/org/apache/logging/log4j/log4j-api/2.8.2/log4j-api-2.8.2.jar
/C:/Users/johnp/.m2/repository/org/apache/logging/log4j/log4j-core/2.8.2/log4j-core-2.8.2.jar
/C:/Users/johnp/.m2/repository/junit/junit/4.12/junit-4.12.jar
/C:/Users/johnp/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.3/lib/idea_rt.jar
However, where it actually is found is here (deleting hp.obo.gz causes a null pointer exception):
C:\Users\johnp\Desktop\git_stuff\boqa\src\main\resources
I don't see how it got this location given the above output (it seems similar to /C:/Users/johnp/Desktop/git_stuff/boqa/target/test-classes/
and
/C:/Users/johnp/Desktop/git_stuff/boqa/target/classes/). Any help would be appreciated. Thanks!

Right click on a folder and "mark directory as" -> "Resources Root". This will configure everything behind the scenes in IntelliJ to work

Related

How to set JsonTemplateLayout eventTemplateUri outside of classpath in Log4j2

In Log4j2's JsonTemplateLayout, I have no problem using eventTemplateUri: "classpath:LayoutTemplate.jsson" with json file located in rc/main/resources.
However, I would need to keep this file outside of class path. so I would like to use file location something like he way we add log fileName: c:\...
But it's throwing an error when I use eventTemplateUri: "C:\ ....\LayoutTemplate.json"
rror message is " Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLa
yout for element JsonTemplateLayout: java.lang.RuntimeException: failed reading URI: C:...
Did I miss anything here?
is it possible to place this json file outside of class path?
Thanks!
All *Uri configuration knobs in JsonTemplateLayout expect a URI string. In your case, the URI scheme is missing. The eventTemplateUri should look like file:///C:/path/to/LayoutTemplate.json in your case. For internals, see how o.a.l.l.l.template.json.util.Uris.readUri(String,Charset) is implemented.

How to fix limax.zdb.XError: dbhome "zdb" not exist?

here is the error:
`limax.zdb.XError: dbhome "zdb" not exist
at limax.zdb.Zdb.testMeta(Zdb.java:130)
at limax.zdb.Zdb.start(Zdb.java:144)
at limax.provider.XmlConfig$StartZdb.lambda$0(XmlConfig.java:410)
at limax.xmlconfig.Service$Loader$TaskList.run(Service.java:108)
at limax.xmlconfig.Service$Loader.runTaskBeforeEngineStart(Service.java:257)
at limax.xmlconfig.Service$Loader.startNetEngine(Service.java:298)
at limax.xmlconfig.Service.startNetEngine(Service.java:350)
at limax.xmlconfig.Service.run(Service.java:372)
at forview.server.Main.main(Main.java:8)`
here is what's in my service-server.xml:
`<Zdb autoKeyInitValue="0" autoKeyStep="4096"
checkpointPeriod="60000" corePoolSize="30" dbhome="zdb"
deadlockDetectPeriod="1000"
defaultTableCache="limax.zdb.TTableCacheLRU"
edbCacheSize="65536" edbLoggerPages="16384" jdbcPoolSize="5"
marshalN="1" marshalPeriod="-1" procPoolSize="10"
schedPoolSize="5" snapshotFatalTime="200" zdbVerify="true">
<Procedure maxExecutionTime="0" retryDelay="100" retryTimes="3" trace="WARN"/>
</Zdb>`
Probably I was trying to build a provider using limax in eclipse, but when I run it something goes wrong.Can someone please help me? Thanks very much.
ok,I create a new folder named "zdb" in my project and everything is ok now. orz

Run an ABCL code that uses cl-cppre

With reference to my previous question,
Executing a lisp function from Java
I was able to call lisp code from Java using ABCL.
But the problem is, the already existing lisp code uses CL-PPCRE package.
I can not compile the code as it says 'CL-PPCRE not found'.
I have tried different approaches to add that package,
including
1) how does one compile a clisp program which uses cl-ppcre?
2)https://groups.google.com/forum/#!topic/cl-ppcre/juSfOhEDa1k
Doesnot work!
Other thing is, that executing (compile-file aima.asd) works perfectly fine although it does also require cl-pprce
(defpackage #:aima-asd
(:use :cl :asdf))
(in-package :aima-asd)
(defsystem aima
:name "aima"
:version "0.1"
:components ((:file "defpackage")
(:file "main" :depends-on ("defpackage")))
:depends-on (:cl-ppcre))
The final java code is
interpreter.eval("(load \"aima/asdf.lisp\")");
interpreter.eval("(compile-file \"aima/aima.asd\")");
interpreter.eval("(compile-file \"aima/defpackage.lisp\")");
interpreter.eval("(in-package :aima)");
interpreter.eval("(load \"aima/aima.lisp\")");
interpreter.eval("(aima-load 'all)");
The error message is
Error loading C:/Users/Administrator.NUIG-1Z7HN12/workspace/aima/probability/domains/edit-nets.lisp at line 376 (offset 16389)
#<THREAD "main" {3A188AF2}>: Debugger invoked on condition of type READER-ERROR
The package "CL-PPCRE" can't be found.
[1] AIMA(1):
Can anyone help me?
You need to load cl-ppcre before you can use it. You can do that by using (asdf:load-system :aima), provided that you put both aima and cl-ppcre into locations that your ASDF searches.
I used QuickLisp to add cl-ppcre (because nothing else worked for me).
Here is what I did
(load \"~/QuickLisp.lisp\")")
(quicklisp-quickstart:install)
(load "~/quicklisp/setup.lisp")
(ql:quickload :cl-ppcre)
First 2 lines are only a one time things. Once quickLisp is installed you can start from line 3.

Maven. Nested properties filtering doesn't work

I have two property files:
#environment.properties
env = production
and second file is:
#commons.properties
production.port = 123
test.port = 567
Also,I have resource file which need be filtered by environment.properties file and commons.properties file and copied.
The resource-file contains:
${${env}.port}
So,I want to filter my resource file with first file and get:
${production.port}
and then I want to filter it with second filter file and get:
123
I use maven 3.2.5 and the resource-file isn't filtered at all.
I know that there's issue related with this problem:
https://jira.codehaus.org/browse/MRESOURCES-70 But it still unresolved.
So,my question is - is there any solution to resolve this problem? (actually,I think that resource-plugin should be modified for work with nested property filtering).
And second question - does exist any way to avoid this problem by refactoring,I mean any other architecture solution. Or, what would you do if you had same problem?

About Path normalize() in Java

For the following code, the aPath turns out to be D:\ OCPJP7\ NIO2\ src\SubPath.java. Why is the programs element gone?
Path aPath = Paths.get(" D:\\ OCPJP7\\ programs\\..\\ NIO2\\ src\\.\\ SubPath.java");
aPath = aPath.normalize();
Because the normalization replaced the .. programs' parent directory.
So you have NIO2 as a sub-folder of OCPJP7.
Similarly, . goes away as it's redundant (indicates current directory within context).
Because the programs element is followed by \\..\\ which means "to go up one directory level". This sequence removes the \\programs\\ part from your path.

Categories

Resources