cancel
Showing results for 
Search instead for 
Did you mean: 

Problem to run a JAR File (MDM Java API)

Former Member
0 Kudos

Hi Experts,

I have an issue with some Java Program, i got the code from a sap note (0001240587). The program do or clean the Workflow Completed Tasks of the MDM Repository.

I build the project and it runs perfect in my NWDS (7.0); but when I export the program to a JAR File (sap note recomendation) it fails and send this message: "Java Virtual Machine Launcher: Could not find the main class. Program will exit".

I tried to export in any different ways of JAR. I though my SDK or JRE version is the problem, but i export the JAR File in the server and is the same result. Also include the JAR MDM Java API Files in the project, etc.

Please i appreciate your help, see the code below.

Best regards.

Jonas Pitta

This is the code:

import com.sap.mdm.session.*;

import com.sap.mdm.workflow.WorkflowTask;

import com.sap.mdm.workflow.commands.DeleteWorkflowJobCommand;

import com.sap.mdm.workflow.commands.RetrieveWorkflowTasksCommand;

import com.sap.mdm.commands.CommandException;

import com.sap.mdm.net.ConnectionException;

public class DeleteCompletedWorkflowJobs {

// The next parameters must be changed according to your environment

private final static String SERVER_NAME = "serverName";

private final static String REPOSITORY_NAME = "repositoryName";

private final static String USER_NAME = "userName";

private final static String PASSWORD = "password";

/**

  • @param args

*/

public static void main(String[] args) {

try {

DeleteCompletedWorkflowJobs test = new DeleteCompletedWorkflowJobs();

UserSessionContext ctx = test.createSessionContext(SERVER_NAME, REPOSITORY_NAME, USER_NAME, PASSWORD);

test.deleteWorkflowJobs(ctx, WorkflowTask.Type.COMPLETED);

// the COMPLETED should not be changed!

} catch (Exception e) {

e.printStackTrace();

e.getMessage();

}

}

public DeleteCompletedWorkflowJobs() {

}

public UserSessionContext createSessionContext(String serverName, String repositoryName, String userName, String password) throws SessionException {

UserSessionContext ctx = new UserSessionContext(serverName, repositoryName, userName);

SessionManager.getInstance().createSession(ctx, SessionTypes.USER_SESSION_TYPE, password);

return ctx;

}

public void deleteWorkflowJobs(UserSessionContext ctx, int taskType)

throws ConnectionException, CommandException, SessionException {

RetrieveWorkflowTasksCommand cmd = new RetrieveWorkflowTasksCommand(ctx);

cmd.setTaskType(taskType);

cmd.execute();

WorkflowTask[] tasks = cmd.getWorkflowTasks();

DeleteWorkflowJobCommand cmd1 = new DeleteWorkflowJobCommand(ctx);

for (int i = 0; i < tasks.length; i++) {

cmd1.setJobId(tasks<i>.getJob().getId());

cmd1.execute();

}

}

}

Edited by: Jonas Pitas on Mar 18, 2010 4:00 PM

Edited by: Jonas Pitas on Mar 18, 2010 4:01 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Jonas,

From [java.sun.com|http://java.sun.com/docs/books/tutorial/deployment/jar/run.html]

JAR Files as Applications

You can run JAR-packaged applications with the Java interpreter. The basic command is:

java -jar jar-file

The -jar flag tells the interpreter that the application is packaged in the JAR file format. You can only specify one JAR file, which must contain all the application-specific code.

Before you execute this command make sure the runtime environment has an information of which class within the JAR file is the application's entry point.

To indicate which class is the application's entry point, you must add a Main-Class header to the JAR file's manifest. The header takes the form:

Main-Class: classname

The header's value, classname, is the name of the class that's the application's entry point.

For more information, see the [Setting an Application's Entry Point section|http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html].

When the Main-Class is set in the manifest file, you can run the application from the command line:

java -jar app.jar

To run the application from jar file that is in other directory, we need to specify the path of that directory as below: java -jar path/app.jar

where path is the directory path at which this app.jar resides.

So to fix the problem add DeleteCompletedWorkflowJob to the Main-Class header to the JAR file's manifest.

Regards,

Ventsi Tsachev

Technology Development Support (J2EE Engine)

SAP Labs, Palo Alto, Ca (USA)

Former Member
0 Kudos

Hi Ventsi,

Sorry for my late answer, but I didn't receive email notification on my inbox of this topic.

This issue I was solved using the Last version of Eclipse (not the NWDS) wich has an option of export "Executable JAR File". Actually it works in the DEV Environment without problems.

But, I have been working from 3 days ago about run the similar JAR File but in my QAS Environment (win 64 bits). The execution is different and equal at the first time in DEV Environment with the same message error.

By luck I saw your message, I run the jar file with the Line Command you said and "It Works". Thank you so much.

Finally, I implemented an script (BAT File) to call the JAR File. Of this way I can automate the process with a Task Scheduling on the Server.

Best Regards

Jonas Pitta

SAP Netweaver Consultant