官术网_书友最值得收藏!

Which application classes to archive

The next step in creating a shared archive includes specifying the application classes to be included. Examine the myCDSlog.log file that you created in the preceding section. It doesn't include each class or interface that is defined in the core Java API.

Similarly, even though your application might include a lot of classes, you need not include all of them in the shared archive file, simply because not all of them are required at startup. This also reduces the size of the shared archive file.

Here's an example to find the application classes that should be added to the shared archive. To start with, create a jar file of your application files.

Let's create four skeleton class files in the com.ejavaguru.appcds package:

// Contents of Cotton.java 
package com.ejavaguru.appcds; 
public class Cotton {} 
 
// Contents of Plastic.java 
package com.ejavaguru.appcds; 
public class Plastic {} 
 
// Contents of PlasticBottle.java 
package com.ejavaguru.appcds; 
public class PlasticBottle extends Plastic {}  
 
// Contents of Wood.java 
package com.ejavaguru.appcds; 
public class Wood {}

And here's the content of the AppCDS class, which uses one of the preceding classes. It isn't defined in the same package:

// Contents of class AppCDS.java 
import com.ejavaguru.appcds.*; 
class AppCDS { 
    public static void main(String args[]) { 
        System.out.println(new Plastic()); 
    } 
} 

If your directory structure matches your package structure, you can create a jar file using the following command:

To determine the application classes that should be placed in the shared archive, execute the following command:

java -Xshare:off  
     -XX:DumpLoadedClassList=myappCDS.lst 
     -cp appcds.jar 
      AppCDS 

On execution of the previous command, myappCDS.lst records the fully qualified name (separated using \) of all classes (approximately 500) that were loaded by JVM. It includes both the core API classes and your application classes.

The following screenshot includes a few of these class names from the myappCDS.lst file. I've highlighted the names of two application files included in this list—AppCDS and com/ejavaguru/appcds/Plastic:

If you revisit the code of the AppCDS class, you'll notice that it uses just one class, that is, Plastic, from the com.ejavaguru.appcds package. The other classes from the same package are not loaded because they are not used. If you want to load other specific classes, you should use them in your application.

After accessing the list of application files to be included in the shared archive, you can move forward and create it.

主站蜘蛛池模板: 盈江县| 汝城县| 吉安市| 三明市| 泽普县| 海伦市| 南江县| 城市| 石城县| 内江市| 肇源县| 万州区| 安西县| 海淀区| 讷河市| 新乡县| 礼泉县| 高邮市| 宁波市| 九台市| 宁德市| 双辽市| 大埔区| 四会市| 余姚市| 夏河县| 江达县| 松阳县| 石屏县| 青岛市| 花莲县| 兴业县| 瓦房店市| 永胜县| 金门县| 兴义市| 勐海县| 进贤县| 绥德县| 盘山县| 龙门县|