Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

78
Vistas
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?

9 months ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.