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

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.

主站蜘蛛池模板: 贵溪市| 霸州市| 高碑店市| 宁城县| 安庆市| 平遥县| 德格县| 长子县| 商河县| 陕西省| 沧源| 汪清县| 济阳县| 获嘉县| 商南县| 新乐市| 武强县| 阿荣旗| 江源县| 高雄市| 石柱| 塔城市| 赞皇县| 玉屏| 中西区| 南郑县| 大关县| 阳新县| 莱州市| 江门市| 镇江市| 太谷县| 嘉峪关市| 正镶白旗| 丹江口市| 海盐县| 新营市| 夏河县| 崇仁县| 揭西县| 白城市|