简体   繁体   English

修改jdk文件夹中的src.zip文件

[英]Modify src.zip file in jdk folder

Can I modify src.zip (it contains java classes predefined ) so that i 我可以修改src.zip (它包含预定义的java类 ),以便我

first unzip and then add my personal package and zip and replace the src.zip with this new src.zip i modified. 首先解压缩 ,然后添加我的个人包zip并用我修改过的新src.zip 替换 src.zip。

so that i can import them just like any other classes. 所以我可以像任何其他类一样导入它们。

The src.zip contains the source files not the class files and it won't be part of the built in classpath either. src.zip包含源文件而不是类文件,它也不是内置类路径的一部分。

If you have to import your classes, you have to keep you other dependent jars in the classpath. 如果必须导入类,则必须在类路径中保留其他相关的jar。

Check out the Java tutorial on the CLASSPATH . 查看CLASSPATH上的Java教程。 That provides an extensible means of adding libraries for Java usage which doesn't impact the original install, and can be segregated between running processes. 这提供了一种可扩展的方法来为Java使用添加库,这不会影响原始安装,并且可以在运行的进程之间进行隔离。

The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes. CLASSPATH变量是告诉应用程序(包括JDK工具)查找用户类的一种方法。 (Classes that are part of the JRE, JDK platform, and extensions should be defined through other means, such as the bootstrap class path or the extensions directory.) (属于JRE,JDK平台和扩展的类应该通过其他方式定义,例如引导类路径或扩展目录。)

The preferred way to specify the class path is by using the -cp command line switch. 指定类路径的首选方法是使用-cp命令行开关。 This allows the CLASSPATH to be set individually for each application without affecting other applications 这允许为每个应用程序单独设置CLASSPATH,而不会影响其他应用程序

You'll rarely have to touch the JDK/JRE install, and I would strongly recommend against it. 您很少需要触及JDK / JRE安装,我强烈建议您不要这样做。 By using mechanisms such as the above, each app can specify its own libs, and you can swap between variants of the JDK/JRE without having to ensure each deployment is modified. 通过使用上述机制,每个应用程序都可以指定自己的库,并且可以在JDK / JRE的变体之间进行交换,而无需确保修改每个部署。

What you want is set the classpath . 你想要的是设置类路径

Of cause, you can add your classes to the rt.jar file, but I highly recommend not to do so. 当然,您可以将类添加到rt.jar文件中,但我强烈建议您不要这样做。

How to set the classpath 如何设置类路径

src.zip folder will not be included in java classpath, yes you can add your own classes in it. src.zip文件夹不会包含在java类路径中,是的,你可以在其中添加自己的类。 But in order to add it your classpath ,it needs to be compiled and the resulting class files you can add use. 但是为了将它添加到类路径中,需要编译它,并且可以添加使用的结果类文件。 But its not recommended to modify jdk source, unless you know exactly what you are trying to do. 但是不建议修改jdk源代码,除非你确切知道你要做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM