パネルに作業ディレクトリを表示する必要があります。
私は使用しますString value = System.getProperty("user.dir")
。その後、この文字列をラベルに付けましたが、コンソールに次のメッセージが表示されます。
The method getProperty(String, String) in the type System is not applicable for the arguments (String).
エクリプスを使っています。
あなたはGWT 101を通過していないと思います.クライアント側でやみくもにJAVA CODEを使用することはできません.
JAVA から GWT でサポートされているクラスとメソッドのリストを見つけることができます。 https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation
システムのみの場合、以下がサポートされています。
err, out,
System(),
arraycopy(Object, int, Object, int, int),
currentTimeMillis(),
gc(),
identityHashCode(Object),
setErr(PrintStream),
setOut(PrintStream)
あなたの場合、サーバー側コードで System.getProperty("user.dir") を実行し、RPC またはその他のサーバー側 gwt 通信技術を使用してアクセスします。
System.getProperty("key") はサポートされていませんが、System.getProperty("key", "default") はサポートされていますが、システム プロパティ自体がないため、デフォルト値のみが返されます。
gwt コンパイル中に作業ディレクトリが必要な場合は、カスタム リンカーまたはジェネレーターを使用し、ビルド時にシステム プロパティを取得して、パブリック リソース ファイルとして出力する必要があります。
リンカーの場合、gwt がダウンロードして必要なコンパイル時のデータを取得できる外部ファイルをエクスポートする必要があります。ジェネレーターの場合は、必要な文字列をコンパイル済みソースに挿入するだけです。
これは、実際には非常に興味深いリンカーのスライドショーです。
http://dl.google.com/googleio/2010/gwt-gwt-linkers.pdf
リンカーと余分な http リクエストを使用したくない場合は、ジェネレーターも使用できます。これはおそらくはるかに簡単 (かつ高速) です。
interface BuildData {
String workingDirectory();
}
BuildData data = GWT.create(BuildData.class);
data.workingDirectory();
次に、ジェネレーターを作成する必要があります。
public class BuildDataGenerator extends IncrementalGenerator {
@Override
public RebindResult generateIncrementally(TreeLogger logger,
GeneratorContext context, String typeName){
//generator boilerplate
PrintWriter printWriter = context.tryCreate(logger, "com.foo", "BuildDataImpl");
if (printWriter == null){
logger.log(Type.TRACE, "Already generated");
return new RebindResult(RebindMode.USE_PARTIAL_CACHED,"com.foo.BuildDataImpl");
}
SourceFileComposerFactory composer =
new SourceFileComposerFactory("com.foo", "BuildDataImpl");
//must implement interface we are generating to avoid class cast exception
composer.addImplementedInterface("com.foo.BuildData");
SourceWriter sw = composer.createSourceWriter(printWriter);
//write the generated class; the class definition is done for you
sw.println("public String workingDirectory(){");
sw.println("return \""+System.getProperty("user.dir")+"\";");
sw.println("}");
return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING
,"com.foo.BuildDataImpl");
}
}
最後に、インターフェイスでジェネレーターを使用するよう gwt に指示する必要があります。
<generate-with class="dev.com.foo.BuildDataGenerator">
<when-type-assignable class="com.foo.BuildData" />
</generate-with>