0

So, let's say I have a jar file called "a.jar" and another jar file called "b.jar".

In the b.jar we have a class called "c.class" and in the a.jar we have a class called "getmesomething.class" with a main function.

From the "getmesomething.class" I'd like to access the "c.class" methods and stuff.

But I do not know how to access "b.jar/c.class" from the main function in "a.jar/getmesomething.class".

I hope I spelled everything right and it isn't too confusing. :-)

sbndh
  • 19
  • 1
  • 4
  • 1
    You should see what is java classpath. Good answer here https://stackoverflow.com/questions/219585/including-all-the-jars-in-a-directory-within-the-java-classpath – Abhishek Garg Jul 27 '19 at 20:09
  • If you have that jar in your classpath, you can import it in your java file like any other java class. – Ashvin Sharma Jul 27 '19 at 20:11
  • all jars (and directories) listed on the classpath will be used to find a class. but the classpath used when starting the application with `java -jar start.jar` will be the one specified in that JAR-file (in its manifest file); if started without the `-jar` option, the system environment CLASSPATH or the one passed with the `-cp` option will be used – user85421 Jul 27 '19 at 20:15

2 Answers2

1

You're actually using classes (import) from other .jar's every time your write java code - using libs from the jdk. As a side note, in java, the convention is to use capitals for a class name, so you may want to use: GetSomething.java (.class), or simply A, B, C)

Each .jar will have multiple packages, so the only thing you have to do is:

import C

or, if the class C is in a package:

import package.x.y.C

The only constraing is to have both .jars in the classpath

You may find this tutorial to guide you (found it by googling for: java learn packages and classes)

azbarcea
  • 3,323
  • 1
  • 20
  • 25
  • 1
    there is no need for `import` at all - it is only *needed* to avoid having to write the fully qualified name of a class everywhere it is used – user85421 Jul 27 '19 at 20:33
-1

can you try using java decompiler plugin, decompile the .class file, then copy the code and add it to your project. idk if you can use the .class file because its codified (if you opent ir with sublime, you will si 0 & 1 xD)

  • Can you add some more context around your answer, for example links to decompilers and how to use them? – atymic Aug 06 '19 at 03:34