0

I have two Jar files Suppose A.jar and B.jar

Inside in A.jar I have one Js file i.e. abc.js with structure same as like Dynamic web project structure.

Ex- wepapp/resources/js/abc.js

I want to read this Js file on another Jar i.e. B.jar. and A.jar is not include in B.jar they both are separate Jar using Java code.

1 Answers1

0

As I can see, here described same problem (or here). I guess it should help you.

EDIT

From these links:

Solution 1

Use a classpath wildcard.

jsvc -cp globalclasspath/*:daemons/service.jar (...) 

Solution 2

To read data in JARs not on the classpath, use URLClassLoader. The general algorithm is this:

  1. Find the list of JARs in the globalclasspath directory.
  2. Create a URLClassLoader from this list of JARs.
  3. Look up the resource you want from the URLClassLoader instance.

To find JARs on the classpath, I used ResourceList from the StackOverflow article "Get a list of resources from classpath directory."

Solution 3

In that case, you need to add both the jars in the class path and execute the below command - where com.schemas.Loader will be your Loader class.

java -cp a.jar;b.jar com.schemas.Loader 

And after that you will be able to get resource file as:

InputStream is = getClass().getResourceAsStream("/com/schemas/your-file.js");
Aceccop
  • 126
  • 6