2

I'm trying to use a .class file I downloaded for a uni project. I don't have the .java file to go with it. I am using netbeans.

  • I tried just adding it to the project src folder
  • I tried using "add JAR/folder" on libraries and adding the directory containing it
  • I also tried creating a JAR file of the directory containing it and adding that

Greatly appreciate any suggestions

8
  • How do you define "to use it"? Commented Oct 24, 2015 at 14:49
  • Nobody should provide a "library" as a .class file. A library should be provided as a jar file, along with documentation. With just a .class file, there is no way, without decompiling it, to know what package it belongs to, and thus where to put it in a project. Commented Oct 24, 2015 at 14:55
  • does your created jar have the correct package structure? Commented Oct 24, 2015 at 14:55
  • FatGiant - I want to create objects of the class Commented Oct 24, 2015 at 14:59
  • 1
    Download a java decompiler from the internet, decompile the class file into a java file and then add it to your project. Only way to use the file without guessing every method. Commented Oct 24, 2015 at 15:35

1 Answer 1

2

You should do two things:

  • Create a jar of the class file you received
  • Create an overview which methods the classfile offers

For the latter you have at least two options. One is to use a decompiler (some authors of APIs deny you to use this) like JD-GUI. The second options is to use javap, which comes with your JDK (I link to Java 8, but it exists in prior versions too). Simply call javap yourfile.class and you will see which method signatures the class offers.

But the easiest way to see the classes / methods inside the .class file is JD-GUI, so if you are not running into any legal issues use that approach.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.