gpt4 book ai didi

java - tomcat + Jenkins + Java EE 源 = 编译失败

转载 作者:行者123 更新时间:2023-12-01 14:43:47 25 4
gpt4 key购买 nike

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

目标是每晚构建一个使用 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>

最佳答案

您当前的所有错误都与 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>

关于java - tomcat + Jenkins + Java EE 源 = 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15674040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com