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

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.

主站蜘蛛池模板: 鞍山市| 自贡市| 武宁县| 陇南市| 克拉玛依市| 鹤峰县| 灵台县| 吴旗县| 宝鸡市| 循化| 芜湖市| 大悟县| 恩施市| 五华县| 澎湖县| 洛浦县| 沙河市| 安吉县| 个旧市| 乌拉特中旗| 大余县| 旌德县| 平昌县| 四川省| 繁昌县| 河源市| 钟山县| 和林格尔县| 乐业县| 左权县| 高密市| 汉源县| 衡南县| 江津市| 吉木乃县| 上林县| 方山县| 钟山县| 交城县| 冷水江市| 沁水县|