Porting Windows MyEclipse Web projects to Debian

Source: Internet
Author: User

Windows first MyEclipse is handy, but porting MyEclipse's Web project to Debian is a bit of a hassle. Of course, if it is Ubuntu, you can just install MyEclipse. This will only be for Debian's porting process with no graphical interface.

1. Provisioning Environment (JDK+APACHE+TOMCAT+MYSQL) (of course, no database is needed)

2. Migrate the original project to Linux.

Mainly divided into the above two parts of the story.

=========================

1.1 JDK

I downloaded the jdk.tar.gz package, which is a bit different on the installation and RPM packages.

1.1.1 Jdk is uploaded to Debian (recommended for WINSCP, easy and graphical).

1.1.2 Configuring the environment variables for the JDK: add the following three statements in the/etc/profile and exit after saving

# Vim/etc/profile

Export java_home=/usr/lib/jvm/java-6-sun-1.6.0.24/export PATH= $JAVA _home/bin: $PATHexport CLASSPATH =.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar: $CLASSPATH

1.1.3 Making environment variables effective

# Source/etc/profile

1.1.4 inspection Environment changed installation success. Enter the following to see if the JDK version number can appear. Or write a Hello world, compile and run with Javac,java, you can output the statement on it. This is a lot of online, just look for a bit.

# Source/etc/profile

=========================

1.2 Apache-tomcat

I am the two installed together, the download is the APACHE-TOMCAT.TAR.GZ installation package. More convenient, completely do not install ...

1.2.1 Upload the installation package to Debian and find a folder to unzip the installation package

# tar ZXVF apache-tomcat-5.5.34.tar.gz

1.2.2 then a folder appears in the current directory: apache-tomcat-5.5.34. Go to the Bin directory in this folder, command-line input

#./startup.sh

Start the server. This is the time to enter http://you_id:8080 in the browser to see the Tomcat Welcome page.

Of course, if your Debian has a separate IP, then the you_id replaced with an independent IP, no ...

The server is not busy to import the project before it is well equipped. First with MySQL

"The above code and instructions are from or refer to: http://www.linuxde.net/2011/10/1401.html"

==========================

1.3 MySQL

1.3.1 Direct installation with Apt-get

# sudo apt-get install Mysql-server

I don't know why I've given so many tutorials to install MySQL online, and it's complicated. This is much simpler, a word on it, and use it as well.

1.3.2 Add a user. I always use root, because it is my own use, no matter.

#/usr/bin/mysqladmin-u Root Password 123456

That's it, root user, 123456 password

1.3.3 Modify the character encoding. If the data is stored in Chinese, it will be displayed in the database. In this case, the result is empty when using the where xxx= "dddd" query. So to modify the/etc/my.cnf file:

Each of the following is best to add the following words, try not to delete the original statement. Of course, there is a conflict, whichever is the following:

[Client]default-character-set=UTF8 [Mysqld]datadir=/var/lib/Mysqlsocket=/var/lib/mysql/Mysql.sockuser=mysql# Disabling Symbolic-links are recommended to prevent assorted security riskssymbolic-links=0#default-character-set=Utf8character-set-server=Utf8init_connect= ' SET NAMES UTF8 '[Mysql]no-auto-Rehashdefault-character-set=UTF8 [Mysqld_safe]log-error=/var/log/Mysqld.logpid-file=/var/run/mysqld/mysqld.pid

1.3.4 restarting the server

This time will be all right. Of course, if the database already has Chinese data before doing 1.3.3, this Chinese data should not be displayed properly

Re-import once (1.3.3 and 1.3.4 both refer to: http://www.linuxde.net/2011/10/1401.html)

=========================

Up to this point, the environment is complete and now it's time to start porting. Take, for example, a small example of a simple servlet that I wrote myself.

=========================

The structure is as shown above. It is important that the Java file box in the package below Src Web_inf lib and web. XML below.

Bookitem.java

 Public classBookitemextendshttpservlet{ Public voiddoget (httpservletrequest request, httpservletresponse response) {printwriter out; Try{ out=Response.getwriter (); Out.println ("A Bookitem page");        } Catch(IOException e) {//TODO auto-generated Catch block//out.println ("Something Else Failed");E.printstacktrace (); }            }             Public voidDepost (httpservletrequest request, httpservletresponse response) {doget (request, response); }    }

Xml

<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "2.5"xmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  <welcome-file-list>    <Welcome-file>index.jsp</Welcome-file>  </welcome-file-list>    <servlet>      <Servlet-name>Test</Servlet-name>      <Servlet-class>Com.bookiten.BookItem</Servlet-class>  </servlet>  <servlet-mapping>      <Servlet-name>Test</Servlet-name>      <Url-pattern>/test</Url-pattern>  </servlet-mapping></Web-app>

In this form, open the server program in MyEclipse and enter http://localhost:8080/Test/test in the browser to see the "a Bookitem page" of the printout

This step is successful, stating that the program under window will work correctly. And put it under Debian.

Special NOTE: This program must first be compiled once, and then copied to Debian. Otherwise the classes file cannot be parsed under Debian (well, that's probably what it means)

Porting is very simple, you just need to move two folders.

1) First of all, we will be in the Debian extracted Apache-tomcat/webapps directory, create a new folder, called it Test, is the root node of the tree structure below.

test|--web-inf|   | --classes|   |   '--com|   |       '--bookiten|   |           '--bookitem.class|   | --lib|   '--web. xml '--com '--    bookiten        '--Bookitem.java

Then we can see that there are two folders under the test root node, namely Web-inf and COM

Yes, these two folders are directly uploaded from the MyEclipse project just now. There is no need to make any changes. It is worth noting that the Com.bookiten package is under the SRC folder. Under Windows, the SRC folder is more useful. But under Debian, there's no need to have SRC.

2) Restart the server. Go to the Apache-tomcat/bin directory and restart the server by entering the terminal as follows

./shutdown.sh./startup.sh

3) Enter Http://you_ip/test/test in the browser to see the "a Bookitem page" output

It is important to note that the URL we entered under Windows is Test/test, and the Test/test is entered under Debian. Be sure to distinguish the case.

Because under Windows, the project name of MyEclipse is called Test, so you use test/test under Windows

Under Debian, the folder in our heart is test, so we use test/test under Debian.

This also shows that your project name, you can change to anything.

========================================

If the project does not involve database operations, you can do so here. But if the database is involved, it is not much more complicated. The key is to import the Mysql.jar package (reference from: http://blog.163.com/[email protected]/blog/static/3814738020097604524363/)

① Download the JDBC driver for MySQL, mine is the Mysql-connector-java-5.1.7.jar package. You can go anywhere on the Internet.

② the Mysql.jar package to the Debian directory.

③ Modify environment variables. When we installed the JDK above, we had an environment variable. Now add the absolute path to the Mysql.jar package in path.

Export path= $JAVA _home/bin:$JRE _home/bin:/home/software/mysql-connector-java-5.1.7.bin.jar : $PATH

The areas needing attention are already marked red. Unlike Windows, Debian's environment changes to be separated by colons, not semicolons. Need attention.

④ then copy this Mysql.jar package to the Apache-tomcat/lib directory (of course, all the jar packages used in the MyEclipse project will be tested in this directory)

⑤ Almighty Reboot Server

Attention:

1. The user name and password for accessing the database in MyEclipse is best as in Debian. Because the code needs to be compiled in order to be used in Debian, it is ineffective to modify the source only in Debian. So the user name and password of the database are best kept consistent

2. Or in MyEclipse, first compile and then copy the source files and Web-inf to Debian.

You can then access it on your browser.

Bon appetite~

Porting Windows MyEclipse Web projects to Debian

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.