Java &. Net Virtual Machine streamlining (released by greenjvm & greendotnet)

Source: Internet
Author: User
Tags dotnet

Small Tool to streamline the size of JRE: http://blog.csdn.net/cping1982/archive/2008/09/02/2865198.aspx

Project address: http://code.google.com/p/greenvm/

Keywords: JRE, streamlining, compression, JVM, java. net, virtual machine, green software, minimum space, Unbox, compression, green, greenjvm



Updated to version 0.1.1.4 on January 1, September 6.

Change:

Add the [set_start_main_class_auto_load] parameter. When this parameter is set to true, the program will set the class where the main function is located to automatically start upon startup.

Added the initialization interface settings. The parameters are as follows:

  1. // Use the initial interface before the program starts. (If this parameter is set to false, the following settings are invalid)
  2. Set_start_init = true
  3. // Use the initial interface Image
  4. Set_start_image%init.bmp
  5. // When set to true, the initial form is automatically centered, and the top and left are invalid.
  6. Set_start_location_auto = true
  7. // Set the X axis of the initial form on the desktop
  8. Set_start_location_left = 100
  9. // Set the Y axis of the initial form on the desktop
  10. Set_start_location_top = 100
  11. // Set the display time of the initial form
  12. Set_start_time = 1000.

PS: the JRE section in this Article refers to Sun JRE.

As we all know, Java can run on almost all operating systems, including windows, Mac, or Linux.

For Java applications of any organization or individual, as long as your application needs to be transplanted or released on multiple operating systems, it is very easy to port existing applications from one system to another, Because Java uses the virtual machine mechanism and can independently interpret and execute the class without operating system constraints.

But there are also advantages and disadvantages. For many programs, this also means that your users must obtain JRE support, that is, they need to install JVM. However, the reality in our country is that many people don't let him download and install JRE by themselves. You just want to install the [next] installation program for him, i'm afraid he can't even make the next step ...... |

In view of this, I tried to provide a solution named greenjvm, which is the green JVM.

Greenjvm is a small program designed for greening Java applications. It was developed in C ++ (a small application that was written last night, and the code prototype was previously posted on the blog: start class through exe ). Invocation (Execution file), a VM. cfg (configuration file), such:

The functions are very simple, but the jretaken from the decompressed java. EXE file is used to directly schedule JVM. dll. But such a small program can easily implement the green release of Java software.


Take the yoyoplayer of Li Qianli ice brother as an example (ice brother blog: http://www.blogjava.net/hadeslee/), we all know that this is
A very good Java music player is well known in the Java circle. Unfortunately, compared with the well-known software such as Jing, the people who know about it are even more rare than Hua Nanhu.
However, the software penetration rate is low for a variety of reasons, but for Java applications, the root cause is the relationship between JVM installation. Just like the principle of "Mom is a woman", the runtime environment of Java programs must be
The compatible JRE of the released version exists, otherwise it will not work. That is, the threshold. I do not know how many common users are out of the Java application.


You may say this is a trivial matter. Indeed, there is certainly no problem for our Java Programmers. But unfortunately, for the vast majority of common users, especially the immature hundreds of millions of Chinese netizens
(I mean the average value of software knowledge ...... In fact, there are many cool people ......), Installing JRE is almost an unimaginable task; unless they have reasons to use it, they need to download third-party software
The program is definitely the first time to pass (the general principle of using software is one: simple to use, trouble to use); virtually increases the difficulty of Java software popularization, obviously, this is a good process.
But it can only be circulated in Java circles.

In fact, we can use simple technical means to break through this restriction and easily turn Java applications into green software. This frees users from the need to hesitate and gives them the confidence to use Java programs.

This process takes only three steps:

1. Compress Your JRE:


Currently, greenjvm supports extracting files by using RAR or zip.

2. Set VM. cfg:

The configuration of VM. cfg is as follows:

  1. [Loon]
  2. /* Virtual Machine decompression method. version 0.1 only provides RAR and ZIP files. rar is recommended for Windows platforms (built-in unrar. dll is called, so local files are not required.
  3. WinRAR exists. You can delete unrar. DLL using zip )*/
  4. Set_unpack_method = RAR
  5. // VM compressed package name, which must be configured in the same path as VM. cfg
  6. Set_vm_name = JRE. Pack
  7. // Check the local JVM version. If the value is lower than the expected value, use the built-in JVM. Otherwise, the local VM runs first.
  8. Set_start_require_version = 1.6
  9. // The jar to be loaded. Multiple packages are separated ';'.
  10. Set_start_jar_path = fps_test.jar
  11. // Main class to be executed
  12. Set_start_main_class = org/test/ballpanel
  13. // Optional. Try to get the JVM path from the specified environment variable. If yes, run the local JVM first.
  14. // Set_start_env = java_home

3. Publish an application. In this case, you only need a folder to fully accommodate the entire Java application.

Now let's take a look at the space usage of a basic and complete jre1.6 compressed package (excluding the EXE file under bin) and yoyoplayer, such:



Compared with the mb jre, the total size of 20 mb is too small. You only need to directly drop the folder to the user and tell the user to "double-click the EXE file to execute". This program can run normally without having to explain or explain anything.

However, Rao is the case. The 20 mb music player is too large compared with the 2 MB or so, which is still unacceptable to many ordinary users. They will not consider the Java features, just think about what you can do in MB. How do you need 20 mb? The level is definitely not good, no ......", Java programmers are crying together ~~~. To avoid this kind of situation, we need to make some articles on the size of JRE.

Just like the human brain activity area, compared to each of our applications, JRE also has at least 20 MB (more than a lot) of space to be wasted and never used for life, the only role of components and class libraries in these regions is to occupy hard disk space greedy ~ Therefore, finding these regions and reducing them can minimize the program volume. (Though sun or many other JVM providers oppose this, we are only experimenting with it.) Besides, I think they will also open the JVM customization service sooner or later. )

Take yoyoplayer as an example. In fact, we only need to retain the audio support, AWT/swing support, and network support in JRE. The remaining parts can be deleted.

In the following example, I made a simplified JRE compressed package, such:


Only 8 Mb space is used to complete all functions of yoyoplayer.

We put the JRE and yoyoplayer together, but the total size is only a little more than 9 MB, and yoyoplayer can still run normally in a non-JRE system. The effect is as follows:

Of course, if we continue to delete the file, the occupied space will definitely decrease to a certain extent. I think it can at least compress the JRE to less than 6 MB. But it is of little practical significance. After all, it is not embedded development, for 1, 2 Mb is not worth the effort ....... In fact, for the vast majority of Java applications, it is more than enough to occupy up to 9 MB space after compression, and there is room for further streamlining.

As shown in the following example, this is an FPS speed measure program that I have previously posted on my blog. The effect is as follows:


Now I use a simplified JRE for AWT and test it on another computer without a Java environment. The result is as follows:

As you can see, the program runs normally, and the number of FPS increases significantly. It does not weaken the performance because the JVM is called directly.

This fully supports the JRE of the AWT component and the execution program to form an rarfile, which is about 4 MB (PS: Since the most occupied JRE has been compressed, so it doesn't really make much sense to compress it ......), In fact, the size of the local program is almost the same.

However, even a 4 mb jre can't be said to be very small. If you are willing to streamline it in depth, a 2 mb jre can run more than enough of the loonframework-game (not yet released) of the publisher. For the Runtime Library, compare rmxp (Game Development toys in ruby ......) It is much smaller.

 

These several Mb Java applications can be carried with you on the USB flash drive, and can be run directly on the USB flash drive (of course, due to the API dependency, unless I re-create a Startup File for other platforms, it only supports systems that provide Win32 APIs.) If you don't need it, you can directly delete the file, which is environmentally friendly, safe, non-polluting, and standard green food, if you don't buy it, check it out ~

Make an installation file (the green software cannot be equivalent to the software that does not need to be installed. After all, the installation is only a deployment process and has no substantial relationship with the green software. As long as the existing system configuration is not changed, software independent of local system components can be called green software, the software that registers a bunch of messy items in the system upon execution cannot be green .), The size of the program will be further reduced.

Taking yoyoplayer as an example, It is absolutely possible to provide a 5 MB or even 4 MB green application to the user. Compared with the MB space occupied by apsaravideo player 5.2.1, it cannot be seen that there is a big difference between the two. Ordinary music lovers have no reason not to download it.

Once they use it, they will gradually discover the subtleties of the Java application. He will find that no matter what system he uses in the future, he will be unable to extricate himself from using this software.


Project address: http://code.google.com/p/greenvm/

--------------------------------------------

Version 0.1.1 released:

 
Project address: http://code.google.com/p/greenvm/

The [set_local_jre_update] item is added. You can use this item to run the local JRE automatic update command.

A Java lightning-like game was released together (for the source code, see the package). A total of three small bosses were set up. It is released using greenjvm, so it can run on a Windows system without JRE loaded. (N an antique written long ago ...... Let's take a look ......).

Go to SourceForge to apply for a project at 1.0 ...... Loonframework is not finished yet ......


Version 0.1.1.3 released:

Project address: http://code.google.com/p/greenvm/

Supports unzipping 7z compressed packages. We recommend that you use this format to compress virtual machines.

_____________________________________________________________________________________________________________
_____________________________________________________________________________________________________________

Greendotnet0.1.0

GreendotnetIt is an application transplanted according to greenjvm. The goal is to implement the green release of the. netframework virtual machine.

Greendotnet 0.1.1

1. This program is a very simple. Net program without installation and release tool, which can meet the needs of the green release and use of desktop applications developed in most. Net framework2.0 and below environments.

2. At present, this program does not try the virtual. Net Runtime Environment (one is hard to write, the other is very lazy, and the third is a Java programmer, understand? ^ ......), After the virtual machine is virtualized, greendotnet.exe will be directly connected to the simplest. NET environment deployed in windows, so there is no impact on the program running efficiency.

3. Only system is deleted from the VM compressed package. web (if you want to implement the functions such as encoding, otherwise the heap will be about 5 MB |), keeping all other linked libraries (such as the system required for database operations. data, etc. Do not delete it yourself ~), Therefore, most operations can be used normally in this environment.

4. Because a real Windows environment is used for deployment, the encrypted or obfuscated. Net program can still run normally in this environment.

5. Compared to the use of billing tools such as salamander. Net linker (including the use of the flying letter runtime framework), this is just a short. Net deployment method, so there will be no copyright or charges.

Description of related documents:

Greendotnet.exe: the Startup file that will act as a local environment probe and deploy the. NET environment.

VM. cfg: configuration file, which determines the operations performed by greendotnet.exe on the system.

DOTNET. pack (8 Mb): a compressed Virtual Machine package generated in the 7z format. Currently, only.. NET 2.0 does not guarantee that applications developed in versions earlier than 2.0 can run normally in this environment.

The VM. cfg configuration is as follows:

  1. [Loon]
  2. // VM decompression method. Currently, three compression methods, rar, zip, and 7z, are supported.
  3. Set_unpack_method = 7z
  4. // VM compressed package name, which must be configured in the same path as VM. cfg
  5. Set_vm_name = DOTNET. Pack
  6. // Check the local. Net version. If the value is lower than the expected value, use built-in. net. Otherwise, the local virtual machine runs first.
  7. Set_start_require_version = 1.1
  8. // The EXE file to be executed, which must be in the same path as VM. cfg
  9. Set_start_main_exe1_comicstars.exe

Project address: http://code.google.com/p/greenvm/

Example program:

Zero is a cartoon download tool. net online cartoon retrieval and download tools, using. netframework1.1 Development (use. net is purely because of convenient Drag Control |), released as the example program of greendotnet.

Related Article

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.