Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:33:25+00:00 2026-06-12T23:33:25+00:00

Does the Java Compiler API support manifest-only jar files with Class-Path entries in the

  • 0

Does the Java Compiler API support manifest-only jar files with Class-Path entries in the classpath arguments?

I am trying to use the Java Compiler API in Maven Surefire tests, but it seems that the Java Compiler API, or more precisely the ToolProvider.getSystemJavaCompiler(), does not handle manifest-only jars of Surefire properly.

Here is a code snippet that shows a failing test

    new File("target/out").mkdir();
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    URLClassLoader classLoader = (URLClassLoader)Thread.currentThread().getContextClassLoader();

    // create classpath
    StringBuilder path = new StringBuilder();
    for (URL url : ((URLClassLoader) classLoader).getURLs()) {
        if (path.length() > 0) {
            path.append(File.pathSeparator);
        }
        String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8");
        path.append(new File(decodedPath).getAbsolutePath());
    }
    System.err.println(path);

    // compile
    List<String> options = Arrays.asList(
      "-classpath", path.toString(),      
      "-s", "target/out",
      "src/test/java/com/mysema/codegen/SimpleCompilerTest.java");
    int compilationResult = compiler.run(null, null, null,
            options.toArray(new String[options.size()]));
    if (compilationResult != 0) {
        Assert.fail("Compilation Failed");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:33:26+00:00Added an answer on June 12, 2026 at 11:33 pm

    I ran into a similar issue running embedded jetty with jsp compilation inside of surefire unit tests. The easier solution was to configure the surefire plugin to not use the manifest-only jar

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <useManifestOnlyJar>false</useManifestOnlyJar>
        </configuration>
      </plugin>
    

    The harder solution was to expand the class path to include jar files referenced from manifest class-path fields

    static List<String> getClassPathForJspCompiler() throws IOException {
        List<String> classPath = Lists.newArrayList(System.getProperty("java.class.path")
                .split(File.pathSeparator));
        return expandManifestClassPathElements(classPath);
    }
    
    private static List<String> expandManifestClassPathElements(List<String> classPath)
            throws IOException {
        for (int i = 0; i < classPath.size(); i++) {
            String element = classPath.get(i);
            if (element.endsWith(".jar")) {
                for (String manifestElement : getManifestClassPath(element)) {
                    // add to the end of the class path so it will get processed
                    if (!classPath.contains(manifestElement)) {
                        // only add if not already present to prevent cyclic loop
                        classPath.add(manifestElement);
                    }
                }
    
            }
        }
        return classPath;
    }
    
    private static List<String> getManifestClassPath(String jarFilePath) throws IOException {
        File jarFile = new File(jarFilePath);
        if (!jarFile.isFile()) {
            return ImmutableList.of();
        }
        Manifest manifest = new JarFile(jarFile).getManifest();
        if (manifest == null) {
            return ImmutableList.of();
        }
        String manifestClassPath = manifest.getMainAttributes().getValue(
                Attributes.Name.CLASS_PATH);
        if (manifestClassPath == null) {
            return ImmutableList.of();
        }
        // split at all spaces that are not preceded by a backslash
        return Lists.newArrayList(manifestClassPath.split("(?<!\\\\) "));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Java Compiler API to compile some java class. That
echo $CLASSPATH /home/user/tomcat/lib/server-api.jar echo $JAVA_HOME .:/usr/lib/jvm/java-6-sun but when I try to compile .java which
I noticed a compiler API in JDK 7. Does this mean that a Java
Does Java have an equivalent to .NET resource (.resx) files for localization? In .NET,
Does java has library exception class which means actually not an error, but good
Does the Java Compiler optimize a statement like this if (a == true) {
I'm trying to analyze Java source files with Clojure but I couldn't find a
I'm trying to compile my java file to class. It is a plugin to
I am trying to compile the java class on: http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld with Jetty web service.
Does Java guarantee array initialization? Let's say I use the code char[] uuid =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.