在glassfish 3中运行时编译JUnit类

时间:2014-03-17 11:11:59

标签: java maven junit glassfish-3 java-compiler-api

我在我的应用程序中运行JUnit测试,但是这些JUnit测试是在运行时创建和编译的。我正在加载一个文本模板,替换一些类标签,并希望在运行时使用java中的javax.tools.Compiler编译这个源代码。

我正在glassfish 3上部署和运行这个应用程序,这似乎是问题,编译器无法找到JUnit库(但它包含在.war中)并抛出编译异常。创建的JUnit测试源代码将编译,没有语法错误或类似的东西。

应用程序是通过maven构建的,这是pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.phoenix</groupId>
<artifactId>WebService</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>WebService Jersey Webapp</name>
<build>
    <finalName>PhoenixWebService</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
            <version>3.1</version>
        </plugin>
        <plugin>
            <groupId>org.glassfish</groupId>
            <artifactId>maven-glassfish-plugin</artifactId>
            <version>2.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey-version}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>${jersey-version}</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.7</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey-version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey.jersey-test-framework</groupId>
        <artifactId>jersey-test-framework-grizzly2</artifactId>
        <version>${jersey-version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.embedded</groupId>
        <artifactId>gf-embedded-api</artifactId>
        <version>1.0-alpha-4</version>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>de.phoenix</groupId>
        <artifactId>library</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time-hibernate</artifactId>
        <version>1.3</version>
    </dependency>


    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate-version}</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.24</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<properties>
    <jersey-version>1.17.1</jersey-version>
    <hibernate-version>3.6.10.Final</hibernate-version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<repositories>
    <repository>
        <id>glassfish.java.net</id>
        <name>GlassFish Maven Repository</name>
        <url>http://download.java.net/maven/glassfish</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>m2.java.net</id>
        <name>Java.net Maven 2 Repository</name>
        <url>http://download.java.net/maven/2</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>phoenixNexus</id>
        <name>Phoenix Maven 2 Repository</name>
        <url>http://meldanor.dyndns.org:8081/nexus/content/groups/public/</url>
        <layout>default</layout>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>m2.java.net</id>
        <name>Java.net Maven 2 Repository</name>
        <url>http://download.java.net/maven/2</url>
        <layout>default</layout>
    </pluginRepository>
</pluginRepositories>

<distributionManagement>
    <repository>
        <id>phoenixNexus</id>
        <name>Internal Releases</name>
        <url>http://meldanor.dyndns.org:8081/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>phoenixNexus</id>
        <name>Internal Releases</name>
        <url>http://meldanor.dyndns.org:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

我正在使用CharSequenceCompiler(http://www.ibm.com/developerworks/library/j-jcomp/)的一点修改版本来在运行时编译类。 编译器只使用jdk类来处理源代码。

有什么想法吗?

0 个答案:

没有答案