Project development experience-how to deal with multiple projects at the same time

Source: Internet
Author: User
Tags addchild

Project development experience-how to deal with multiple projects at the same time

 

If several projects are developed at the same time, it is easy to publish them to Tomcat for debugging. Use the "add and remove deployment" menu provided by myeclipse to publish or cancel a release. For example, there are four projects A, B, C, and D.

To run Project A, release project a separately. To run Project B, release Project B. at the same time, remove other projects that have been released under tomcat, so that the switchover is repeated, especially when the project is large and it takes about half a minute to release the project.

If the figure is convenient, release four projects A, B, C, and D at the same time, which saves the trouble of repeatedly "add and remove", but on the other hand, the Tomcat startup process is slower than releasing only one program. If the program changes a lot, Tomat needs to be started repeatedly and started once and waited for a minute or two. A waste of time affects your mood. In addition, when multiple projects are released at the same time, Tomcat runs out of memory.

 

There is a way to solve the problem. Modify the conf/server. xml file in the Tomcat root directory. Add the context element to the host element and configure the virtual path. To release a project named A, add the following code:

<Context Path = "/a" docbase = "D:/Eclipse/workspace/A/webapp"> </context>

D:/Eclipse/workspace/A/webapp is the project path. The root folder Name of the web project created by myeclipse is webroot. In the preceding example, the root folder name is webapp. Make sure to modify the name.

 

Another method is to use embedded tomcat. (Myeclipse creates a web project named Haha)

Step 1: Download embedded tomcat. 5.0 with JDK 5.5 and jdk1.5.

Step 2: remove the J2EE class library of the Haha project and change it to JDK.

Step 3: Download the embedded Tomcat contains the Lib folder and conf folder, add the jar package in the Lib folder to the WEB-INF/lib folder of the Haha project, add the entire conf folder to webroot.

Step 4: Compile the Tomcat startup class.

 

Note the following when using embedded Tomcat:

1) the startup code of 5.5 and 5.0 is different. Please note that. And JDK should be properly matched.

2) embedded Tomcat requires the tool. jar package to dynamically compile JSP. It is best to add JDK to the running path (emphasize Step 2 again ).

3) In the Tomcat startup class, set the value of catalinahome, as shown in the following code line: tomcat. setcatalinahome (catalinahome );

I guess that when Tomcat is started, it will automatically find the conf/web in the catalinahome path. XML file, as the default web. XML (default web. XML), usually this file contains information for processing JSP files. when using embedded tomcat, make sure that the file exists. Here, repeat Step 3.

4) do not include any conflicting packages in classpath. It is best to run a simple or empty project first. Then run the real project.

There are many examples on the Internet. Here we use a self-built (Tomcat 5.0)

//--------------------------------------------------------

// Myembeddedtomcat. Java

Import org. Apache. Catalina. startup. Embedded;
Import org. Apache. Catalina. engine;
Import org. Apache. Catalina. Host;
Import org. Apache. Catalina. context;
Import org. Apache. Catalina. connector;

Import java. Io. file;
Import java.net. inetaddress;

/**
*/
Public class myembeddedtomcat {
Private string webrootpath; // Web Application Path
Private string contextpath; // The Name Of The web context.
Private string catalinahome = "D:/myeclipse/workspace/embeddedtomcat/webroot ";
Private Boolean reloadable = true; // whether to allow hot swapping of class

Private embedded Tomcat; // embedded Tomcat

Public myembeddedtomcat (){

Webrootpath = "D:/myeclipse/workspace/A/webroot ";


Contextpath = "/tomcat ";
}

/**
* Start Tomcat
*/
Public void startup () throws exception {

Tomcat = new embedded ();
Engine engine = tomcat. createengine ();
Tomcat. setcatalinahome (catalinahome );

Host host = tomcat. createhost ("localhost", webrootpath );
Context context = tomcat. createcontext (contextpath, webrootpath );
// Context. setaltddname (getwebxmldirectory (); // set the Web. xml location
If (reloadable) Context. setreloadable (true );
Host. addchild (context );
Engine. addchild (host );
Engine. setdefaulthost (host. getname ());

Engine. setname ("embeddedserver ");
Tomcat. addengine (engine );
Connector conne=
Tomcat. createconnector (inetaddress. getbyname ("0.0.0.0"), 8080, false );
Tomcat. addconnector (connector );
Tomcat. Start ();
}

/**
* Terminate Tomcat
*/
Public void Shutdown () throws exception {
Tomcat. Stop ();
}

Public static void main (string [] ARGs ){
Try {

Long begin = system. currenttimemillis ();
String workdir = "D:/myeclipse/workspace/embeddedtomcat/webroot/work ";
Delfolder (workdir );
System. Out. println ("Work directory is deleted, use" + (system. currenttimemillis ()-begin) + "Ms ");
Begin = system. currenttimemillis ();
New myembeddedtomcat (). startup ();
System. Out. println ("Tomcat server started, use" + (system. currenttimemillis ()-begin) + "Ms ");
} Catch (exception e ){
E. printstacktrace ();
}
}

// Delete a folder
// Complete absolute path of the param folderpath folder

Public static void delfolder (string folderpath ){
Try {
Delallfile (folderpath); // delete all contents
String filepath = folderpath;
Filepath = filepath. tostring ();
Java. Io. File myfilepath = new java. Io. File (filepath );
Myfilepath. Delete (); // delete an empty folder
} Catch (exception e ){
E. printstacktrace ();
}
}

// Delete all objects in the specified folder
// Complete absolute path of the param path folder
Public static Boolean delallfile (string path ){
Boolean flag = false;
File file = new file (PATH );
If (! File. exists ()){
Return flag;
}
If (! File. isdirectory ()){
Return flag;
}
String [] templist = file. List ();
File temp = NULL;
For (INT I = 0; I <templist. length; I ++ ){
If (path. endswith (file. separator )){
Temp = new file (path + templist [I]);
} Else {
Temp = new file (path + file. Separator + templist [I]);
}
If (temp. isfile ()){
Temp. Delete ();
}
If (temp. isdirectory ()){
Delallfile (path + "/" + templist [I]); // delete the files in the folder first
Delfolder (path + "/" + templist [I]); // Delete the empty folder.
Flag = true;
}
}
Return flag;
}

}

//-------------------------------------------------------------------------

 

These are my personal gains when debugging embedded Tomcat over the past few days. If you have any shortcomings or errors, please correct them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.