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 6680483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:28:49+00:00 2026-05-26T04:28:49+00:00

Running the Java Compiler from a JUnit test is pretty simple using the Java

  • 0

Running the Java Compiler from a JUnit test is pretty simple using the Java Compiler API. The test checks that I can load new code using a temporary classloader and that the cleanup works, etc

My problem is compiling and/or running the test using Maven.

If I add the java compiler using a dependency, I must set the scope to test. If I do that, the tools.jar will be added to the classpath when the tests are being compiled which means that there will be two Java compilers on the classpath.

The same is true for the scope runtime but that will also add the Java compiler to my artifact, making it leak. All other scopes are even worse.

How can I solve this?

  • 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-05-26T04:28:49+00:00Added an answer on May 26, 2026 at 4:28 am

    Are you sure that you need the java compiler dependency at all? Without any special (compiler) dependency the Java Compiler API works for me (as it’s part of the JDK).

    You can set the target VM version with the options parameter of getTask, for example:

    final List<String> options = new ArrayList<String>();
    options.add("-target");
    options.add("1.3");
    options.add("-source");
    options.add("1.3");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a running Java GWT application, that I can compile using Eclipse. Now
When I am running a junit test from ant I always get: D:\metrike>ant test
We are running an web application that is using Java 64bit 5 gigs of
I now have a running Java program which only lacks of the final step,that
I'd like to generate sequence diagrams of a running java ee application using jtracert
I'm running a simple Java program with below directory structure: MyProject (A project in
I'm having problems with a java.lang.NoClassDefFoundError when trying to run my JUnit tests from
I'm not an expert in Java and I'm pretty new to the whole concept
What are the consequences of running a Java class file compiled in JDK 1.4.2
I've compiled a java project into a Jar file, and am having issues running

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.