0

For our project we needed to compile few class files during run-time, we have started to use JavaCompiler class. Everything works fine in Eclipse however when we tried to build (Maven) and deploy we are getting "package does not exist" error.

Code first:

Files.walk(Paths.get(inputTestcaseFolder))
    .filter(Files::isRegularFile)
    .filter(path -> path.toAbsolutePath().toString().contains(".java"))
    .forEach(fileList::add);

for (Path p : fileList) {
    System.out.println("Test Compiled : " + p.getFileName().toString());
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();           
    compiler.run(null, null, null, p.toString());
    }

Also tried referencing the class path still the same issue

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
                   StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
                   List<String> files = new ArrayList<>();
                   files.add(p.toString());
                   Iterable<? extends JavaFileObject> compilationUnits1 =
                   fileManager.getJavaFileObjectsFromStrings(files);                       
                   optionList.addAll(Arrays.asList("-classpath",System.getProperty("java.class.path")));
                   compiler.getTask(null, fileManager, null, optionList, null, compilationUnits1).call();
                   fileManager.close();

Jenkins Job configuration:

Build Goal and Options:

-e -X clean compile dependency:copy-dependencies exec:java
-Dexec.mainClass="Performance.BaseFixture.Base" -DM2=D:\ -DM2_HOME=C:\apache-maven-3.2.3
-Dmaven.repo.local=D:\ -Dexec.includeProjectDependencies=true

Error:

[DEBUG] Adding project dependency artifact: httpclient to classpath
[DEBUG] Adding project dependency artifact: xmlbeans to classpath
[DEBUG] Adding project dependency artifact: stax-api to classpath
[DEBUG] Adding project dependency artifact: zip4j to classpath
[DEBUG] joining on thread Thread[Performance.BaseFixture.Base.main(),5,Performance.BaseFixture.Base]
[DEBUG] Setting accessibility to true in order to invoke main().
success
Test Compiled : CaseListFlow.java
src\test\java\TestCases\CaseListFlow.java:3: error: package HTTPClient does not exist
import HTTPClient.HTTPResponse;
                 ^
src\test\java\TestCases\CaseListFlow.java:4: error: package HTTPClient does not exist
import HTTPClient.NVPair;
          ^       
Jyothishwar Deo
  • 436
  • 3
  • 10
  • See http://stackoverflow.com/questions/1563909/how-to-set-classpath-when-i-use-javax-tools-javacompiler-compile-the-source – fvu May 12 '16 at 20:53
  • Tried Still the same error --> optionList.addAll(Arrays.asList("-classpath",System.getProperty("java.class.path"))); compiler.getTask(null, fileManager, null, optionList, null, compilationUnits1).call(); fileManager.close(); – Jyothishwar Deo May 12 '16 at 21:20
  • Is there really a hyphen missing at the Maven option `Dexec...`? – Gerold Broser May 12 '16 at 21:40
  • Still the same issue after adding the - hyphen ... – Jyothishwar Deo May 13 '16 at 05:26

0 Answers0