Solved

HowTo nest standalone Java into a MVC package

Posted on 2011-03-10
3
316 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now