These test classes do that between them (with a bit of help from some others):

https://github.com/gratiartis/qzr/blob/master/sctrcd-drools/src/test/java/com/sctrcd/drools/spring/DroolsSpringTest.java

https://github.com/gratiartis/qzr/blob/master/sctrcd-drools/src/test/java/com/sctrcd/drools/spring/DroolsSpringTestConfig.java

You will probably need to follow the path through the code to understand how that application does it.

tl;dr - If you don’t want to do that, then below is a method for creating a KieServices instance; after which, you need something like:

KieContainer kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
KieSession kieSession = kieContainer.newKieSession(SessionConfiguration.getDefaultInstance());


    private void createAndBuildKieServices(DroolsResource[] resources) throws KieBuildException {
        this.kieServices = KieServices.Factory.get();
        this.kfs = newKieFileSystem();
        
        for (DroolsResource resource : resources) {
            log.info("Resource: " + resource.getType() + ", path type="
                    + resource.getPathType() + ", path=" + resource.getPath());
            switch (resource.getPathType()) {
            case CLASSPATH:
                this.kfs.write(ResourceFactory.newClassPathResource(resource.getPath()));
                break;
            case FILE:
                this.kfs.write(ResourceFactory.newFileResource(resource.getPath()));
                break;
            case URL:
                UrlResource urlResource = (UrlResource) ResourceFactory
                        .newUrlResource(resource.getPath());
                
                if (resource.getUsername() != null) {
                    log.info("Setting authentication for: " + resource.getUsername());
                    urlResource.setBasicAuthentication("enabled");
                    urlResource.setUsername(resource.getUsername());
                    urlResource.setPassword(resource.getPassword());
                }
                
                this.kfs.write(urlResource);
                
                break;
            default:
                throw new IllegalArgumentException(
                        "Unable to build this resource path type.");
            }
        }
        
        KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
        
        if (kieBuilder.getResults().hasMessages(Level.ERROR)) {
            List<Message> errors = kieBuilder.getResults().getMessages(Level.ERROR);
            StringBuilder sb = new StringBuilder("Errors:");
            for (Message msg : errors) {
                sb.append("\n " + prettyBuildMessage(msg));
            }
            throw new KieBuildException(sb.toString());
        }
        
        log.info("KieServices built: " + toString());
    }

... where DroolsResource is this:

https://github.com/gratiartis/qzr/blob/master/sctrcd-drools/src/main/java/com/sctrcd/drools/DroolsResource.java