2017-10-23 2 views
0

従来のWAR Spring Webアプリケーションから、現代​​のSpring Boot実行可能ファイルJarに移行する予定のアプリケーションに移行しました。SpringブートアプリケーションでJavaCompiler APIを使用する - コンパイルクラスパスを正しく設定できません

アプリモジュールの1つはJavaCompiler APIを使用してJavaコードを生成し、実行時にコンパイルします。
生成されたコードは、Webアプリケーションのクラスパスに存在する依存関係を必要とし、私たちはおおよそ次のコードを持っていた:ブートでは動作しない、しかし

StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null); 

List<String> optionList = new ArrayList<String>(); 

    // set compiler's classpath to be same as the runtime's 
    String classpathString = System.getProperty("java.class.path"); 
    optionList.addAll(Arrays.asList("-nowarn", 
            "-classpath", 
            classpathString, 
            "-g", 
            "-source", 
            javaVersion, 
            "-target", 
            javaVersion)); 

    Collection classpathFiles = getClasspathJars(classpathString); 
    addPreviousCompiledClassesToClasspathFiles(rootClassPath, classpathFiles); 

    try { 
     File file = new File(getTargetRoot(tempClassPath)); 
     file.mkdirs(); 
     standardFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Lists.newArrayList(file)); 
     standardFileManager.setLocation(StandardLocation.CLASS_PATH, classpathFiles); 

     // adding current dir to the source path, to find the compiled DV 
     if (generateSeparateJarsForEachDecision.equals(NO_JAR)) { 
      standardFileManager.setLocation(StandardLocation.SOURCE_PATH, Lists.newArrayList(file)); 
     } 
    } catch (IOException e) { 
     throw new RuntimeException(e); 
    } 


     List<CharSequenceJavaFileObject> compilationUnits = Lists 
       .newArrayList(new CharSequenceJavaFileObject( StringUtils.capitalize(filename), 
                   toString(javaCode))); 
     JavaCompiler.CompilationTask task = compiler 
       .getTask(writer, standardFileManager, listener, optionList, null, compilationUnits); 
     status = task.call(); 

`` `

を。 クラスパスにはmy-app.jarしか含まれていません。ネストされたjarファイルをタスクの-cpに追加することはできません。働いていたこれらの{absolute-path}/my-app.jar!/BOOT-INF/lib/my-dep.jar {absolute-path}/my-app.jar!/BOOT-INF/lib/*.jar

なし: 私は手動でもそうのような-cpパラメータ彼らに追加​​しようとしました。 <requiresUnpack>タグをビルドに使用することについても考えましたが、クラスパスに追加するために展開されたディレクトリを保持できなかったため、役に立たなかったようです。

答えて

0

同様の問題に直面しています。

スプリングブーツでの制限のようです。

これで、JerseyとTomcatが埋め込まれたスタンドアロンアプリケーションが作成されました。

jarにはすべてのライブラリが含まれており、Javaコンパイラのクラスパスとして設定することができます

関連する問題