Pregunta

I have a sourcecode and in this source are two classes referenced.

Now I want to compile this code via JavaCompiler but therefore I have to first compile the two referenced classes.

Is there a better method than reading the file and search for the classes, to compile them first?

package data.testcases

import org.junit.runner.RunWith;
import org.junit.runners.Suite;


@RunWith(Suite.class)
@Suite.SuiteClasses({
        XTest.class,
        YTest.class
})
public class ASuite {
}

XTest.java and YTest.java are in the same dir as Suite is

¿Fue útil?

Solución

Now I want to compile this code via JavaCompiler but therefore I have to first compile the two referenced classes

No you don't. As long as the Java compiler can find those classes it will compile them automatically. That means that they need to be located in the same directory system as the file you are actually compiling, or else locatable via the -sourcepath option.

Otros consejos

Looking at the docs. for JavaCompiler suggests to me that adding them to the iterable collection of compilationUnits provided to getTask(..) should achieve the desired result.

Yes, there is definitiveliy a better method. Use a build tool like Apache Ant to organize your builds. There are several tutorials included in the Ant Wiki.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top