protected void searchForMain(Path tmpJarDir) {
		try {
			// using Files.walk method with try-with-resources
			try (Stream<Path> paths = Files.walk(tmpJarDir)) {
				List<Path> items = paths.filter(Files::isRegularFile)
					.filter(f -> !f.toFile().getName().contains("$"))
					.filter(f -> f.toFile().getName().endsWith(".class"))
					.collect(Collectors.toList());

				Indexer indexer = new Indexer();
				Index index;
				for (Path item : items) {
					try (InputStream stream = new FileInputStream(item.toFile())) {
						indexer.index(stream);
					}
				}
				index = indexer.complete();

				Collection<ClassInfo> classes = index.getKnownClasses();

				Project project = ctx.getProject();
				if (project.getMainClass() == null) { // if non-null user forced set main
					List<ClassInfo> mains = classes.stream()
						.filter(getMainFinder())
						.collect(Collectors.toList());
					String mainName = getSuggestedMain();
					if (mains.size() > 1 && mainName != null) {
						List<ClassInfo> suggestedmain = mains.stream()
							.filter(ci -> ci.simpleName().equals(mainName))
							.collect(Collectors.toList());
						if (!suggestedmain.isEmpty()) {
							mains = suggestedmain;
						}
					}

					if (!mains.isEmpty()) {
						project.setMainClass(mains.get(0).name().toString());
						if (mains.size() > 1) {
							Util.warnMsg(
									"Could not locate unique main() method. Use -m to specify explicit main method. Falling back to use first found: "
											+ mains.stream()
												.map(x -> x.name().toString())
												.collect(Collectors.joining(",")));
						}
					}
				}

				if (project.getMainSource().isAgent()) {
					Optional<ClassInfo> agentmain = classes.stream()
						.filter(pubClass -> pubClass.method("agentmain",
								STRINGTYPE,
								INSTRUMENTATIONTYPE) != null
								||
								pubClass.method("agentmain",
										STRINGTYPE) != null)
						.findFirst();

					if (agentmain.isPresent()) {
						project.setAgentMainClass(agentmain.get().name().toString());
					}

					Optional<ClassInfo> premain = classes.stream()
						.filter(pubClass -> pubClass.method("premain",
								STRINGTYPE,
								INSTRUMENTATIONTYPE) != null
								||
								pubClass.method("premain",
										STRINGTYPE) != null)
						.findFirst();

					if (premain.isPresent()) {
						project.setPreMainClass(premain.get().name().toString());
					}
				}
			}
		} catch (IOException e) {
			throw new ExitException(1, e);
		}
	}
This class takes a <code>Project</code> and compiles it.
src/main/java/dev/jbang/source/buildsteps/CompileBuildStep.java