tomcat + Jenkins + Java EE source =编译失败

时间:2013-03-28 03:59:48

标签: java java-ee ant jboss jenkins

我很难在非常简单的Java EE源代码中运行在tomcat6上运行的Jenkins(在Centos 6.x上)。我已经尝试下载JBoss但找不到Java EE jar文件,所以我可以在我的ANT脚本中包含这些文件。我从Oracle下载了JavaEE,它是.sh shell脚本(80mb),我想通过提取或编译各种jar来“安装”java ee。问题是它不会运行,因为Oracle shell脚本需要运行X11实例(GUI)......但这是一个无头服务器。

目标是让每晚使用JavaEE构建一个项目。

我需要以某种方式找到如何使用JBoss只为它的java ee库(所以我可以编译我的代码)或者需要以某种方式让oracle的服务工作?或者我的设置还有其他选择吗?

这是我的Jenkins / Ant日志输出:

build-project:
 [echo] JUtils: /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/build.xml
[javac] Compiling 27 source files to /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/target/tmp
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:21: error: package javax.mail does not exist
[javac] import javax.mail.Message;
[javac]                  ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:22: error: package javax.mail does not exist
[javac] import javax.mail.MessagingException;
[javac]                  ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:23: error: package javax.mail does not exist
[javac] import javax.mail.Session;
[javac]                  ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:24: error: package javax.mail does not exist
[javac] import javax.mail.Transport;
[javac]                  ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:25: error: package javax.mail.internet does not exist
[javac] import javax.mail.internet.AddressException;
[javac]                           ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:26: error: package javax.mail.internet does not exist
[javac] import javax.mail.internet.InternetAddress;
[javac]                           ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:27: error: package javax.mail.internet does not exist
[javac] import javax.mail.internet.MimeMessage;
[javac]                           ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:51: error: cannot find symbol
[javac]             throws AddressException, MessagingException {
[javac]                    ^
[javac]   symbol:   class AddressException
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:51: error: cannot find symbol
[javac]             throws AddressException, MessagingException {
[javac]                                      ^
[javac]   symbol:   class MessagingException
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:63: error: cannot find symbol
[javac]         Session session = Session.getDefaultInstance(props, null);
[javac]         ^
[javac]   symbol:   class Session
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:63: error: cannot find symbol
[javac]         Session session = Session.getDefaultInstance(props, null);
[javac]                           ^
[javac]   symbol:   variable Session
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:64: error: cannot find symbol
[javac]         MimeMessage message = new MimeMessage(session);
[javac]         ^
[javac]   symbol:   class MimeMessage
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:64: error: cannot find symbol
[javac]         MimeMessage message = new MimeMessage(session);
[javac]                                   ^
[javac]   symbol:   class MimeMessage
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:65: error: cannot find symbol
[javac]         message.setFrom(new InternetAddress(from));
[javac]                             ^
[javac]   symbol:   class InternetAddress
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:67: error: cannot find symbol
[javac]         InternetAddress[] toAddress = new InternetAddress[to.length];
[javac]         ^
[javac]   symbol:   class InternetAddress
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:67: error: cannot find symbol
[javac]         InternetAddress[] toAddress = new InternetAddress[to.length];
[javac]                                           ^
[javac]   symbol:   class InternetAddress
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:71: error: cannot find symbol
[javac]             toAddress[i] = new InternetAddress(to[i]);
[javac]                                ^
[javac]   symbol:   class InternetAddress
[javac]   location: class SendEmail
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:76: error: package Message does not exist
[javac]             message.addRecipient(Message.RecipientType.TO, toAddress[i]);
[javac]                                         ^
[javac] /usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/src/net/snakedoc/jutils/SendEmail.java:82: error: cannot find symbol
[javac]         Transport transport = session.getTransport("smtp");
[javac]         ^
[javac]   symbol:   class Transport
[javac]   location: class SendEmail
[javac] 19 errors

BUILD FAILED
/usr/share/tomcat6/.jenkins/jobs/JUtils-Nightly/workspace/build.xml:54: Compile failed; see the compiler error output for details.

Total time: 4 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE

编辑:( Ant构建脚本)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="JUtils">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../../Program Files/eclipse-jee-juno-SR1-win32-x86_64/eclipse"/>
<property name="JAVAEE_HOME" value="/opt/jboss/modules/**"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<property name="dest_dir" value="target"/>
<property name="tmp_dir" value="tmp"/>
<property name="jar_name" value="JUtils"/>
<path id="javaee.libraryclasspath">
        <pathelement location="${JAVAEE_HOME}"/>
    </path>
<tstamp>
    <format property="build.datestamp" pattern="yyyy-MM-dd" locale="en,US"/>
</tstamp>
<path id="JUtils.classpath">
    <pathelement location="bin"/>
    <pathelement location="lib/h2-1.3.170.jar"/>
    <pathelement location="lib/hsqldb.jar"/>
    <pathelement location="lib/jt400.jar"/>
    <pathelement location="lib/log4j-1.2.17.jar"/>
    <pathelement location="lib/mariadb-java-client-1.1.1.jar"/>
    <pathelement location="lib/mysql-connector-java-5.1.23-bin.jar"/>
    <pathelement location="lib/postgresql-9.2-1002.jdbc4.jar"/>
    <pathelement location="lib/sqlite-jdbc-3.7.2.jar"/>
    <path refid="javaee.libraryclasspath"/>
</path>
<target name="init">
    <mkdir dir="${dest_dir}"/>
    <mkdir dir="${dest_dir}/${tmp_dir}"/>
    <mkdir dir="${dest_dir}/${tmp_dir}/src"/>
    <mkdir dir="${dest_dir}/${tmp_dir}/doc"/>
    <mkdir dir="${dest_dir}/${tmp_dir}/lib"/>
    <mkdir dir="${dest_dir}/${tmp_dir}/META-INF"/>
    <copy includeemptydirs="false" todir="${dest_dir}">
        <fileset dir="src">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
    <copy includeemptydirs="false" todir="${dest_dir}/${tmp_dir}">
        <fileset dir=".">
            <include name="**/*"/>
            <exclude name="target/**"/>
            <exclude name="logs/**"/>
            <exclude name="bin/**"/>
        </fileset>
    </copy>
</target>
<target name="clean">
    <delete dir="${dest_dir}"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project,jar" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac debug="true" debuglevel="${debuglevel}" destdir="${dest_dir}/${tmp_dir}" includeantruntime="false" source="${source}" target="${target}">
        <src path="src"/>
        <classpath refid="JUtils.classpath"/>
    </javac>
</target>
<target name="create_manifest">
    <manifest file="${dest_dir}/${tmp_dir}/META-INF/MANIFEST.MF">
        <attribute name="Manifest-Version" value="1.0"/>
        <attribute name="Website" value="www.snakedoc.net"/>
        <attribute name="Project" value="JUtils-${build.datestamp}"/>
    </manifest>
</target>
<target depends="create_manifest" name="jar">
    <jar destfile="${dest_dir}/${jar_name}-${build.datestamp}.jar" basedir="${dest_dir}/${tmp_dir}"/>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
    <copy todir="${ant.library.dir}">
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </copy>
    <unzip dest="${ant.library.dir}">
        <patternset includes="jdtCompilerAdapter.jar"/>
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    <antcall target="build"/>
</target>
<target name="DBTest">
    <java classname="net.snakedoc.jutils.testsuite.DBTest" failonerror="true" fork="yes">
        <classpath refid="JUtils.classpath"/>
    </java>
</target>

1 个答案:

答案 0 :(得分:1)

您当前的所有错误都与Java Mail有关。

另一方面,使用Maven会使一些依赖性问题变得无足轻重。

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.6</version>
</dependency>