Gradle – add directory to classpath

The application plugin documentation says: Static files to be added to the distribution can be simply added to src/dist I would try putting your config directory into src/dist/lib and continue adding it to your classpath with runtime files(‘src/dist/lib/config’) Note: working around this defect means that config has to go into /lib under src/dist

Jar hell: how to use a classloader to replace one jar library version with another at runtime

I can’t believe that for more than 4 years no one has answered this question correctly. https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html The ClassLoader class uses a delegation model to search for classes and resources. Each instance of ClassLoader has an associated parent class loader. When requested to find a class or resource, a ClassLoader instance will delegate the search … Read more

read file in classpath

Change . to / as the path separator and use getResourceAsStream: reader = new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream( “com/company/app/dao/sql/SqlQueryFile.sql”))); or reader = new BufferedReader(new InputStreamReader( getClass().getResourceAsStream( “/com/company/app/dao/sql/SqlQueryFile.sql”))); Note the leading slash when using Class.getResourceAsStream() vs ClassLoader.getResourceAsStream. getSystemResourceAsStream uses the system classloader which isn’t what you want. I suspect that using slashes instead of dots would work … Read more

What’s the minimum classpath for an Axis2 client?

The minimum jars for the client are: activation-1.1.jar axiom-api-1.2.8.jar axiom-impl-1.2.8.jar axis2-adb-1.5.1.jar axis2-kernel-1.5.1.jar axis2-transport-http-1.5.1.jar axis2-transport-local-1.5.1.jar commons-codec-1.3.jar commons-httpclient-3.1.jar commons-logging-1.1.1.jar httpcore-4.0.jar mail-1.4.jar neethi-2.0.4.jar wsdl4j-1.6.2.jar XmlSchema-1.4.3.jar STAX jars below are not part of Axis2 1.5.1 release and will be needed if your JDK version is less than 6: stax-1.2.0.jar stax-api-1.0.1.jar

I am getting “java.lang.ClassNotFoundException: com.google.gson.Gson” error even though it is defined in my classpath

In case of a JSP/Servlet webapplication, you just need to drop 3rd party JAR files in /WEB-INF/lib folder. If the project is a Dynamic Web Project, then Eclipse will automatically take care about setting the buildpath right as well. You do not need to fiddle with Eclipse buildpath. Don’t forget to undo it all.

Java Spring – How to use classpath to specify a file location?

Are we talking about standard java.io.FileReader? Won’t work, but it’s not hard without it. /src/main/resources maven directory contents are placed in the root of your CLASSPATH, so you can simply retrieve it using: InputStream is = getClass().getResourceAsStream(“/storedProcedures.sql”); If the result is not null (resource not found), feel free to wrap it in a reader: Reader … Read more

In JShell, how to import classpath from a Maven project

You can use the jshell-maven-plugin: mvn com.github.johnpoth:jshell-maven-plugin:1.3:run which will fire up a JShell session with your project’s runtime path. If you want to include your test dependencies just add -DtestClasspath to the command. NOTE: the plugin expects the project to be built already. If not, invoke the appropriate Maven build phase before the plugin e.g: … Read more

Is it possible to mix –class-path and –module-path in javac (JDK 9)?

You can use class path and module path in parallel, but there are a few details to consider. Dependency Module Path ~> Class Path Explicit modules (JARs with a module descriptor on the module path) can not read the unnamed module (JARs on the class path) – that was done on purpose to prevent modular … Read more