からjarファイルからクラスファイルを読み込むことが可能ですので、私は、Javaにかなり新しいですが、私が達成しようとしていることは、私は特定のディレクトリにあると私はなりたいjarファイルを含むリストを持っていますそれらのjarファイル内のクラスファイルを読み込み、クラスファイル内にある文字列をグローバルに検索することができます。は、それが特定のパス
私の現在のコード:
Class<?> clazz; //get the class you need
Field f = clazz.getField("Variable_name");
// if Field f is null, no field exist with the given name
// this is necessary if the field is not public.
f.setAccessible(flag);
// if the field is not static, the parameter is the instance you want the field from
// otherwise it can be null
Object variableValue = f.get(null); // or f.get(clazzInstance);
この特別なクラスローディングやクラスファイルリーダーを必要としない:あなたが特定の名前の変数を求めている場合は
public class Dank
{
public static void main(String[] args)
{
List<File> jarFiles = new ArrayList<>();
File[] mods = new File(System.getProperty("user.home") + "\\AppData\\Roaming\\.minecraft\\mods").listFiles();
for(File file : mods)
{
if(file.isFile())
{
String filename = file.getName();
if(filename.endsWith(".jar")) {
jarFiles.add(file);
// System.out.println(filename);
}
}
}
}
}
なぜ、McForge自身がmod(クラス)を取得する方法を提供しているのですか?あなたは何を探しているのですか?特定のクラス、またはクラスファイル内のデータ?後でもっとたくさんのものがあるから – n247s
すべてのクラスファイルで文字列を検索できるようにしたい場合、その文字列が存在すると特定のイベントが発生した場合 –
'class'ファイル形式の指定があります。 'class'ファイルのセクションの1つに、それで使用されるすべての文字列が含まれています。 – talex