Another face of J2EE:
Application Solution Based on SWT and Java Web START
part 1
Li Feng Tong
(Hebei Finhua Information Technology Co., Ltd., Shijiazhuang, Hebei 050000)
Summary: As an excellent programming language, Java has a prominent superiority in many ways. Especially in the field of enterprise applications, J2EE's position is still universible. In the actual development process, applications constructed above the J2EE system often use browser-based B / S structures to implement the front desk performance. This structure not only removes cumbersome procedural distribution, but also makes the application system easy to maintain and upgrade. However, while obtaining the above advantages, it also brings shortcomings such as the interface control too complicated, and human-machine interactions is not surprising. This article starts from the perspective of solving the shortcomings of existing J2EE development mode, explores how the Eclipse project's SWT library and Sun's Java Web Start technologies are used to achieve the advantages of two structures of C / S and B / S. Program solution.
Keywords: J2EE, SWT, Java Web Start, C / S, B / S
From the birth of a few years, Java has received more and more favors with its unique charm. Whether it is a large enterprise application system, or mobile information equipment development, you can see Java's figure everywhere. In the field of enterprise applications, J2EE has become the first choice for many largest companies in many large enterprises as a mature system architecture.
When the J2EE is selected, it is usually used for three or multi-layer architectures, and the backend is responsible for interaction with the database, while the front end is implemented by the Java application or a browser-based web page. But after a practical test, it is found that these two expressions are not very satisfied. First, use the Java application written by the GUI (graphical user interface) developments in J2SE, which is difficult to accept, regardless of the appearance or speed. Their appearance always looks into the same operating system platform, and the demand for machine configuration seems to be never end. Secondly, although the browser-based web mode is eliminated by the cumbersome program distribution and make the application system easy to maintain and upgrade, the HTML page faces the weak performance of complex application logic, making a good interface to write a good operability. Extremely heavy work. To this end, we need to find another solution.
Figure 1: Containers, components and services in J2EE
Fish, what I want
In November 2001, IBM announced the donation of $ 40 million to the open source Eclipse project. Eclipse is a next-generation IDE (integrated development environment) that replaces IBM's Visual Age for Java, but its goal does not only become a IDE environment specializing in developing Java applications. According to the Eclipse architecture, it will be able to apply to any language development by extended plugins. To learn more about Eclipse, you can access the official website of Eclipse http://www.eclipse.org/.
Most of the programmers who use Eclipse will be amazed in its interface performance. Indeed, whether it is the appearance style or running speed, almost no one will think this is written in Java: The same familiar menu, the same familiar toolbar, the same buttons and dialog boxes ... and this must be due to SWT !
Figure 2: Eclipse integrated development environment
SWT (Standard Widget Toolkit, Standard Widget Toolbox) itself is only a set of underlying graphical interface APIs written in the Eclipse organization in order to develop Eclipse's IDE environment, which does not provide separate SWT packages. But over time, more and more developers have found that SWT has exceeded the AWT and SWING provided by Sun. According to Eclipse official description, the design of SWT components is to provide developers with an efficient, portable and capable of utilizing operating system UI features. Through JNI (Java Native Interface, Java Localization Interface) technology, SWT takes "use for me" provided by the operating system. Only components that are not available in the operating system, SWT will go to a simulation implementation. This design concept not only makes the application to be integrated with the local operating system, but also greatly improve the running speed of the graphics program, which has highly overcomes the congenital defects of AWT and Swing, and has received the majority of Java. Programmer is favored. In use, SWT does not differ from other third-party class libraries. From http://download.eclipse.org/downloads/index.php We can download to the latest SWT package, you can get SWT.jar after decompression, and will not be described in terms of specific environment configuration and class import. The only thing to pay attention to is the JNI localized library file. Because SWT uses JNI technology, it is also necessary to find a corresponding JNI localized library file. The name of the localization library file will be slightly different due to the difference from the version and the operating system. Taking the Windows platform as an example, the dynamic link library corresponding to the latest SWT package is SWT-WIN32-3034.DLL.
Bear's palm, I also want to
No matter what language, applications developed based on C / S (client / server) mode will always have some unpleasant features. Compared with the B / S (browser / server) mode, although there is an advantage of being friendly and interacting with a human-machine interface, its cumbersome release method makes the deployment, maintenance and upgrade of the program. Human headache work. When the number of users exceeds two digits, it is simply a nightmare. Java Web Start may be the terminator of this nightmare.
Figure 3: Java Web START Application Manager
Java Web Start is the application deployment technology launched by Sun, which can be used to download and run the desired application without having to pass a complex installation process. Through Java Web Start, the installation operation of the application is simplified to click on a hyperlink on a web page. Java Web Start downloads all the files required by the program to the local computer and caches so that the application can be launched again at any time in a shortcut or browser at any time. At the same time, it is also responsible for the automatic detection of the program. Whether to start an application in any way, Java Web Start ensures that the latest version is rendered to the user, and the entire process does not need to interact with the user. To learn more about Java Web Start, you can visit http://java.sun.com/products/javawebstart/.
The latest version number of the latest Java Web Start is 1.4.2. It is bundled with Java 2 SDK and JRE (Java Runtime Environment, Java runtime environment). From http://java.sun.com/j2se/1.4.2/download.html we can download to Java 2 SDK and JRE installation packages. Regarding the specific application of Java Web Start technology, we will introduce a detailed introduction to the demo project later.
Fish and bear's pauses are not good?
Up to now, we have introduced two critical technologies for solving the shortcomings of existing J2EE development model: First, SWT, mainly used as the interface performance of the client program; Second, Java Web Start, mainly used as client programs Network release. The next question is how to integrate it into J2EE's architecture to make it a complete solution. In the J2EE architecture, the backend is responsible for interacting with the DJB component, the client of the front desk is looking for and invokes the required by JNDI (Java Naming and Directory Interface, Java Naming and Directory Interface) Functional components. For B / S mode applications, the above process occurs in servlets:
Context ctx = new initialContext ();
Object objref = ctx.lookup ("MysessionBeanhome");
MysessionBeanhome Home = (MySessionBeanhome)
PortableremoteObject.narrow (Objref, MysessionBeanhome.class);
MysessionBean bean = home.create ();
Typically, the web container and JNDI service is integrated in the same application server. Therefore, when the code is created in InitialContext, there is no explicit provision of context.initial_context_factory and context.provider_url. However, if the application is implemented using a C / S mode, then the client program must be explicitly provided by the developer's client program:
Properties Properties = New Properties ();
Properties.put (Context.Initial_Context_Factory,
"com.ibm.websphere.naming.wsninitialcontextfactory");
Properties.Put (Context.Provider_URL, "IIOP: // localhost: 9001");
Context CTX = New InitialContext (Properties);
Object objref = ctx.lookup ("MysessionBeanhome");
MysessionBeanhome Home = (MySessionBeanhome)
PortableremoteObject.narrow (Objref, MysessionBeanhome.class);
MysessionBean bean = home.create ();
For different JNDI services, its initialization parameters are not the same. Here are some common JNDI service initialization parameters:
· File system JNDI service
Java.naming.Provider.URL = file: // C: / Temp
Java.naming.factory.initial = com.sun.jndi.fscontext.reffsContextFactory
· IBM WebSphere JNDI Service
Java.naming.Provider.URL = IIOP: // localhost: 9001
Java.naming.factory.initial = com.ibm.Websphere.naming.wsninitialContextFactory
· BEA WebLogic JNDI Service
Java.naming.Provider.URL = T3: // localhost: 7001java.naming.factory.initial = WebLogic.jndi.wlinitialContextFactory
· Iplanet directory server (LDAP)
Java.naming.Provider.URL = ldap: // localhost: 389
Java.naming.factory.initial = com.sun.jndi.ldap.ldapctXFactory
It should be noted that although the initial chemical plant may not be directly referenced in the program code, the actual runtime JVM will dynamically load it according to the name. Therefore, the developer should also ensure that the initial chemical plant is visible to the client program while distributing applications.
At this point, our solution already has a relatively clear frame: the backend uses the EJB component to interact with the database, the front desk client develops and uses Java Web Start to deploy and publish, the intermediate application server passes JNDI This two links to become a whole.
Conclude
In this article, we give a rough implementation ideas based on the application solution based on SWT and Java Web START. In the next article, we will use the Windows platform as an example, combined with IBM's WSAD 5.0, detail the specific implementation details of this program.
Reference:
· Http://java.sun.com/ java official website
· Http://www.eclipse.org/ Eclipse official website
· Eclipse Getting Started - Eclipse Introduction and Plugin Development, Ni Dapeng
Http://www-900.ibm.com/developerWorks/cn/java/l-eclipse/index.shtml
· SWT: AWT and SWING strong competitors, Ni Dapeng, February 2003
Http://www-900.ibm.com/developerWorks/cn/java/l-swt/index.shtml
About the Author:
Li Feng Tong, Hebei Finhua Information Technology Co., Ltd. software developers, all technologies related to Java, is now mainly engaged in the development of e-government related applications based on J2EE architecture.
Contact information:
E-mail: phoenixtrees@hotmail.com