正如我在之前的问题中指出的那样,我正在尝试为NetBeans多层web应用程序项目设置一个带有Jenkins CI的自动构建系统。
我的Ant目标是clean和debug。Clean工作正常,但在尝试编译项目时调试失败。在我的Jenkins构建的输出中,我看到以下命令:
[PGB Webapp] $ cmd.exe/C '"C:Program Files (x86)Jenkinstoolshudson.tasks.Ant_AntInstallationApache_Antbinant.bat" "- dlib . mysqldriver . C '"classpath=C:/Program Files (x86)/MySQL/MySQL Connector J/MySQL - Connector -java-5.1.31-bin.jar" "- dlib . copylib .jar"classpath=C:/Program Files/NetBeans 8.0/java/ant/extra/org-netbeans-modules-java-j2seproject-copylibstask.jar" "-Dj2ee.server. jar"家= C://wildfly-8.1.0程序文件。最后的"干净调试"& &;退出% %返回码% % "
这是我输出的最后一部分:(对我来说似乎最重要的部分)
library-inclusion-in-manifest:
-do-compile:
[mkdir] Created dir: C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warbuildempty
[mkdir] Created dir: C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warbuildgenerated-sourcesap-source-output
[javac] Compiling 2 source files to C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warbuildwebWEB-INFclasses
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwconfigApplicationConfig.java:6: error: package javax.ws.rs.core does not exist
[javac] import javax.ws.rs.core.Application;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwconfigApplicationConfig.java:8: error: cannot find symbol
[javac] public class ApplicationConfig extends Application {
[javac] ^
[javac] symbol: class Application
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:12: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.GET;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:13: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.Path;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:14: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.PathParam;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:15: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.QueryParam;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:16: error: package javax.ws.rs does not exist
[javac] import javax.ws.rs.Produces;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:17: error: package javax.ws.rs.core does not exist
[javac] import javax.ws.rs.core.MediaType;
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:19: error: cannot find symbol
[javac] @Path("/employees")
[javac] ^
[javac] symbol: class Path
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:29: error: cannot find symbol
[javac] public List<Employee> find(@QueryParam("name") String name) {
[javac] ^
[javac] symbol: class QueryParam
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:27: error: cannot find symbol
[javac] @GET
[javac] ^
[javac] symbol: class GET
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:28: error: cannot find symbol
[javac] @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
[javac] ^
[javac] symbol: class Produces
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:38: error: cannot find symbol
[javac] public Employee findById(@PathParam("id") String id) {
[javac] ^
[javac] symbol: class PathParam
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:36: error: cannot find symbol
[javac] @GET @Path("{id}")
[javac] ^
[javac] symbol: class GET
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:36: error: cannot find symbol
[javac] @GET @Path("{id}")
[javac] ^
[javac] symbol: class Path
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:37: error: cannot find symbol
[javac] @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
[javac] ^
[javac] symbol: class Produces
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:44: error: cannot find symbol
[javac] public List<Employee> findByManager(@PathParam("id") String managerId) {
[javac] ^
[javac] symbol: class PathParam
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:42: error: cannot find symbol
[javac] @GET @Path("{id}/reports")
[javac] ^
[javac] symbol: class GET
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:42: error: cannot find symbol
[javac] @GET @Path("{id}/reports")
[javac] ^
[javac] symbol: class Path
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwrestEmployeeResource.java:43: error: cannot find symbol
[javac] @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
[javac] ^
[javac] symbol: class Produces
[javac] location: class EmployeeResource
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwconfigApplicationConfig.java:17: error: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warsrcjavacomedwconfigApplicationConfig.java:22: error: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] 22 errors
BUILD FAILED
C:Program Files (x86)JenkinsworkspacePGB Webappnbprojectbuild-impl.xml:208: The following error occurred while executing this line:
C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warnbprojectbuild-impl.xml:881: The following error occurred while executing this line:
C:Program Files (x86)JenkinsworkspacePGB Webapppgb-warnbprojectbuild-impl.xml:297: Compile failed; see the compiler error output for details.
Total time: 1 second
Build step 'Start Ant' marked build as failure
Finished: FAILURE
嗯,这里重要的是Java编译器不能定位RESTful Web Services库。我在C:/Program Files/wildfly-8.1.0.Final/modules/system/layers/base/javax/ws/rs/api/main/jaxrs-api-3.0.8.Final.jar.
我没有Ant构建工具的经验,所以我已经搜索并发现了很多关于它,但我似乎无法弄清楚如何添加这个库,以便项目在Jenkins上正确构建。
当前我的build.xml文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project name="pgb" default="default" basedir="." xmlns:ear="http://www.netbeans.org/ns/j2ee-earproject/2">
<description>Builds, tests, and runs the project pgb.</description>
<import file="nbproject/build-impl.xml"/>
<taskdef resource="net/jtools/classloadertask/antlib.xml">
<classpath>
<fileset dir="${basedir}/lib" includes="ant-classloader*.jar"/>
</classpath>
</taskdef>
<!--Add jar to the classpath-->
<classloader loader="system">
<classpath>
<fileset dir="${basedir}/lib" includes="jboss-modules.jar"/>
<fileset dir="${basedir}/lib" includes="jaxrs-api-3.0.8.Final.jar"/>
</classpath>
</classloader>
</project>
文件build-impl.xml(这是导入的)是由NetBeans生成的(您可能已经知道),并且太大而无法在这里显示,此外我无法更改那里的任何内容,因为系统可能会自动更改该文件本身。
无论如何,正如您所看到的,我已经尝试使用我在这里找到的Ant Classloader: https://stackoverflow.com/a/5116470/2541501但是运气不好……我甚至将所需的jar文件添加到项目的lib目录中。
所以,我的问题是:我如何改变我的Ant构建脚本,使Java编译器不抱怨丢失的包(即丢失的jar文件)?
我还担心,如果我在build.xml文件中添加任何目标,它可能与生成的build-impl.xml文件中声明的任何内容冲突。有人知道这个吗?
好的,我的同事发现我们只需要将NetBeans项目的私有属性复制到项目的Jenkins作业的Ant Invoke的properties字段中。
因此,我们的NetBeans项目在nbproject-目录中有一个名为private的目录。在这个private目录中有一个名为private.properties的文件。我们从该文件中获取属性,并将其复制到Ant Invoke的properties字段中。现在我们的Properties字段如下所示:libs.CopyLibs.classpath=C:/Program Files/NetBeans 8.0/java/ant/extra/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.MySQLDriver.classpath=C:/Program Files (x86)/MySQL/MySQL Connector J/mysql-connector-java-5.1.31-bin.jar
j2ee.platform.is.jsr109=true
j2ee.server.domain=C:/Wildfly/standalone
j2ee.server.home=C:/Wildfly
j2ee.server.instance=wildfly-deployer:localhost:8080#standalone&C:\Wildfly
现在我们可以毫无问题地执行所有Ant命令。我们还可以部署通过Jenkins构建的web应用程序。
如果有人想知道,RESTful Web服务可以在WildFly中找到。因此,我们不需要直接包含rest式Web服务的jar,我们所需要的只是为WildFly服务器设置正确的属性。
回想起来,我想说,为NetBeans项目建立一个带有自动构建的持续集成系统并不是那么困难。现在,下一步是包括项目的自动化测试。