HowTo nest standalone Java into a MVC package

Hey experts....
this question should be simpler than I think Im confused with...

If I have a test class that begins with the following code, how can I re-engineer this code to not start by itself but to be packaged into a larger MVC Project and be made available to be called directly by other classes within the package...


I just reconfigure the provided code by the vendor to become a constructor (with the neccessary argument parameters) right ?...


thx Im just still trying to get better at Java... Not a master at churning code (yet) ...
// starts with this public statement
  public static void main(String argv[]) {
    if ( argv == null || argv.length != 3 ) {
      System.err.println("usage: TestConnect <ccapi URL> <campusId> <shared key>");
      System.exit(1);
    }

Open in new window

JAaron AndersonProgramming Architect @ Widener UniversityAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
if you want to call the main from another class you would use

MyClass.main(new String[] { ccapiUrlString, campusId, SharedKey });
0
 
JAaron AndersonProgramming Architect @ Widener UniversityAuthor Commented:
I already have a " main " function in my ViewDefinition class that returns the index.jsp page for the main portion of the beginning webpage...

Im triggering the newly incorporating class into my MVC environment to execute new methods when other methods are triggering...

e.g. when user hits submit on form I am taking that field info from JSP page and pushing it through this new Class to update a service on a remote server...


I think this code is all I have to do make this class available to any/all other classes  of the same package... Ill try compiling and see what happens...
private static final long campusId = 123;
  private static final String urlStr = "https://my.url.API.location.tld";
  private static final String sharedKey = "32fhb9p2348qhq234f";
  public String ccUID;
  public String ccEXP;
	
// jaa Constructor method for initialization by other classes

NewClassAPIManager( ccUsername, ccExpiration ) {
		this.urlStr = urlStr;
		this.campusId = campusId; 
		this.sharedKey = sharedKey;
		this.ccUID = ccUsername;
		this.ccEXP = ccExpiration;	
	}

Open in new window

0
 
objectsConnect With a Mentor Commented:
yes all you need to do is make it available
forget about the main, it is only used/needed to run the class
0
All Courses

From novice to tech pro — start learning today.