samedi 11 août 2018

Java reflection over outside project

I have two projects:

Project 1- Main server

Project 2- repositories for main server

Project 1 is in the path of project 2 (projet 2 implementing methods from project 1).

I want to use reflection to loop through packages in project 2 FROM project 1.

i.e in project 1:

public class VehicleRepository {
    public static List<Vehicle> repository = new ArrayList<>();

    public static void main(String[] args){
      Class<?> vehicleInProject2 = Class.forName("Project2.com.game.vehiclerepo.Toyota");

      System.out.println(""+vehicleInProject2 == null);
    }

}

Java reflection Class.forName only checks in the project it is being called in, so syntax starting with "Project2." will always throw class not found.

How do I get past this?





Aucun commentaire:

Enregistrer un commentaire