import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.job.Job;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectoryInterface;
import org.pentaho.di.repository.kdr.KettleDatabaseRepository;
import org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta;
public class execRepositoryJobs {
private static String jobName = "Job";
public static void main(String[] args) {
try {
KettleEnvironment.init();
KettleDatabaseRepository repository = new KettleDatabaseRepository();
DatabaseMeta databaseMeta = new DatabaseMeta("repository", "MSSQL","Native", "192.169.0.146", "repository", "1433", "sa","sa");
KettleDatabaseRepositoryMeta kettleDatabaseMeta = new KettleDatabaseRepositoryMeta("repository", "ERP", "Transformation description",databaseMeta);
repository.init(kettleDatabaseMeta);
repository.connect("admin", "admin");
RepositoryDirectoryInterface directory = repository.loadRepositoryDirectoryTree();
JobMeta jobMeta = ((Repository) repository).loadJob(jobName, directory, null, null ) ;
// RepositoryDirectoryInterface fooBar = directory.findDirectory("/");
//
// JobMeta jobMeta = repository.loadJob(repository.getJobId(jobName, fooBar), null);
Job job = new Job(repository,jobMeta);
job.start();
job.waitUntilFinished();
if (job.getErrors() > 0) {
throw new RuntimeException(
"There were errors during transformation execution.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}