Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Access Class at runtime with reflections from JAR file

I'm working on a correcting system for assignments for students. Let me try to break my problem down into a simple example.

The projects I want to check look like this:

  • project-name
    • src

      • Task1

        • Solution1.java
        • Solution2.java

Now I want to check if the project has a correct implementation, but I can not assure, that Solution1.java exists, so I'm using reflection to access the classes.

I'm copying a package into the src folder, so the new project looks like this.

  • project-name
    • src

      • Task1

        • Solution1.java
        • Solution2.java
        • Correction
          • Correction.java

I don't know, if the Solution.java actually exists, so I'm using reflections.

Class.forName("Task1.Solution1");

Now I'm compiling everything inside the project and run the Correction.java - file in Linux.

This works fine so far.

In order to speed up the process, I tried to create a Solution.jar file, so I don't have to compile the file for every project. When I run the jar-file I'm getting a ClassNotFound exception, when I try to access Solution1. The jar file lies within the Correction-package.

I'm starting inside the src folder, and I run:

java -jar ./Correction/Correction.jar

Does anyone know, why this might be happening?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!