- Java 11 and 12:New Features
- Mala Gupta
- 401字
- 2021-07-02 12:27:04
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.
- C++ Primer習題集(第5版)
- Android Jetpack開發:原理解析與應用實戰
- C#編程入門指南(上下冊)
- 深入淺出Spring Boot 2.x
- Machine Learning with R Cookbook(Second Edition)
- Hands-On JavaScript High Performance
- Android應用案例開發大全(第二版)
- Spring Boot+MVC實戰指南
- Python網絡爬蟲技術與應用
- ArcPy and ArcGIS(Second Edition)
- LabVIEW數據采集(第2版)
- 虛擬現實:引領未來的人機交互革命
- C++ Data Structures and Algorithm Design Principles
- HTML+CSS+JavaScript前端開發(慕課版)
- 信息安全技術(第2版)