简体   繁体   English

静态资源文件?

[英]A static resource file?

Android uses a static resource file R . Android使用静态资源文件R This file (at least in eclipse) is automatically updated when ever you add new id's of any sort. 每当您添加任何新的ID时,此文件(至少在eclipse中)都会自动更新。 How can I create/implement the same feature in a normal java application? 如何在普通的Java应用程序中创建/实现相同的功能? Is it as simple as just writing an xml parser and just updating the resource file after the xml is modified? 是否像编写xml解析器并在修改xml之后仅更新资源文件一样简单?

In a way, yes. 在某种程度上,是的。 You need to create a custom build script/program which runs at the start of each build (before anything else), scans your resource folder files (and if they are XML files it needs to read in the XML files and parse out the string resources or whatever from those), then write it all to a Java file in some manner (eg R.string_name = "string value"). 您需要创建一个自定义构建脚本/程序,该脚本/程序在每个构建开始时运行(之前没有其他操作),扫描您的资源文件夹文件(如果它们是XML文件,则需要读取XML文件并解析出字符串资源)或其中的任何内容),然后以某种方式将其全部写入Java文件(例如R.string_name =“ string value”)。

Make sure the XML files aren't actually packaged in your .jar, since all that information will be stored inside your Java resources file now. 确保XML文件实际上没有打包在您的.jar中,因为所有这些信息现在都将存储在Java资源文件中。

For things which aren't XML files you could just store the filename as a string in the Java resources file. 对于非XML文件,您可以将文件名作为字符串存储在Java资源文件中。

You didn't specified the type or the use of the resources. 您没有指定资源的类型或用途。 I don't know android, but I'll try to help; 我不懂android,但我会尽力提供帮助。 If you just need to access some resource in your application you can use properties or resource, there are some differences see this other question Properties vs Resource Bundle 如果您只需要访问应用程序中的某些资源,则可以使用属性或资源,请参见其他问题。 属性与资源捆绑

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

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