apache.commons.cli and IProgramBase

Hello group,
I have created a number of jar files for our XI environment with success, but have always chosen to hard-code the parameters (env/user/pass) in the .java file rather than try to pass them in the command line, but I am growing tired of touching my code as it moves through DEV/TEST/PROD

I started playing with the apache commons cli and my test runs fine in the JDK and on my desktop, however when I try to publish the app to XI it runs to success with a java error

Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.commons.cli.Options
	at java.lang.J9VMInternals.verifyImpl(Native Method)
	at java.lang.J9VMInternals.verify(J9VMInternals.java:68)
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:129)
	at java.lang.Class.newInstanceImpl(Native Method)
	at java.lang.Class.newInstance(Class.java:1328)
	at com.crystaldecisions.sdk.plugin.desktop.program.internal.ProgramWrapper.main(ProgramWrapper.java:162)

Has anyone seen this before? Is the IProgramBase interface not playing well with apache.commons.cli? That seems to be the only difference in my testing.

My sample code below (I have created another class for the CLIValidation, but added a chunk here for simplicity):


import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.plugin.desktop.program.IProgramBase;

public class test implements IProgramBase{
	   public static void main (String[] args) { 
		      try { 
		    	  SharedCode(args); 
		      } 
		      catch (Exception ex) { 
		         ex.printStackTrace(); 
		      }
		   }
	   public void run(IEnterpriseSession enterpriseSession, IInfoStore infoStore, java.lang.String[] args) { 
		      try { 
		    	  SharedCode(args); 
		      } 
		      catch (Exception ex) { 
		         ex.printStackTrace(); 
		      } 
		   }
	
		public static void SharedCode(String[] args) {
		//if (CLICheck.main(args)==0){	//The command line arguments were handed to the application correctly.
		try {
			Options opt = new Options();
	        opt.addOption("h",false, "Print help for this application");
	        opt.addOption("s",true, "System");
	        opt.addOption("u",true, "Username");
	        opt.addOption("p", true, "Password");
	        opt.addOption("a", true, "Authentication Type (secEnterprise/secLDAP)");
	        opt.addOption("j", true, "Java Application");
	        BasicParser parser = new BasicParser();
	        CommandLine cl;
			cl = parser.parse(opt, args);
			System.out.println("Hello");
		//}
        }
        catch(ParseException e) {
            e.printStackTrace();
        }
	}
}

cpare :us: (BOB member since 2008-10-06)

The code works from your desktop because the Commons jars are in your classpath, but XI can’t find those jars when executed from the server because it doesn’t know about them. Navigate to your program object in the CMC then go to Properties -> Program Parameters. You should see an option for Classpath. Put the jars some place where your server account can access them and type the path in this field. The error will go away after this is done. By the way, don’t try to reschedule a failed instance after doing this because classpath is stored for each instance; schedule a new job instead.


BoB LoblaW :us: (BOB member since 2007-10-23)

Was there ever a resolution to this thread? I am facing the same challenges with the CLI in my application. The JAR file works fine from my dev workstation and on the AIX server, just not through the CMS.


cpare :us: (BOB member since 2008-10-06)

Did you include it in the classpath parameter of the Program Object?


joepeters :us: (BOB member since 2002-08-29)