Solved

HowTo nest standalone Java into a MVC package

Posted on 2011-03-10
3
321 Views
Last Modified: 2013-11-13
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

0
Comment
Question by:jandersonwidener
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 35099573
if you want to call the main from another class you would use

MyClass.main(new String[] { ccapiUrlString, campusId, SharedKey });
0
 

Author Comment

by:jandersonwidener
ID: 35100162
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
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 35100253
yes all you need to do is make it available
forget about the main, it is only used/needed to run the class
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question