Setup Netbeans project on Jenkins - netbeans

I have a Netbeans Project that I'm trying to build from Jenkins, using ant, in a linux environment.
I have copied the CopyLibStack.jar to /var/lib/Jenkins/nblibs/ and setup in the ant task with the following properties:
-Dj2ee.server.home="/var/lib/jenkins/tomcat/"
-Dlibs.CopyLibs.classpath=/var/lib/jenkins/nblibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
But it doesn’t work; it fails on a <copyfiles> task
If I install Jenkins on windows and set the properties to:
-Dj2ee.server.home="C:\Archivos de programa\Apache Software Foundation\Tomcat 6.0"
-Dlibs.CopyLibs.classpath=C:\\.jenkins\\nblibs\\org-netbeans-modules-java-j2seproject-copylibstask.jar
The project build without problems
If I run the ant task from the terminal with:
ant -file build.xml do-dist test -Dlibs.CopyLibs.classpath="/var/lib/jenkins/nblibs/copylibstask.jar" -Dj2ee.server.home="/var/lib/jenkins/tomcat/"
it builds fine too
I think that the problem is in the user jenkins, but I don't know how to fix it.
What can I do?

I had the same problem, which I have fixed :) (I'm using ubuntu 12.04). Find build.properties in ".netbeans/7.0" and look for the lib that you are missing... copy it to project.properties
Ex:
libs.CopyLibs.classpath=/opt/netbeans-7.0.1/java/ant/extra/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.javaee-api-6.0.classpath=/opt/netbeans-7.0.1/enterprise/modules/ext/javaee-api-6.0.jar

I found a recipe in this link basically you have to have Netbeans installed on your server so you can reuse the build.xml generated by Netbeans.
Create a file jenkins-build.xml at the same level as your build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="BioGatewayWS Stub" default="build" basedir=".">
<!-- create private folders -->
<mkdir dir="nbproject/private"/>
<!--- set variables needed by Ant when outside of Netbeans -->
<propertyfile file="nbproject/private/private.properties">
<!--<entry key="user.properties.file" value="/opt/NetBeans8/build.properties"/>-->
<entry key="user.properties.file" value="C:\Users\jm\AppData\Roaming\NetBeans\8.2\build.properties"/>
</propertyfile>
<!-- Build targets - these just chain a call to the original build file-->
<target name="build">
<!-- <ant dir="${basedir}" target="build"/>-->
<ant dir="${basedir}" target="default"/>
</target>
<target name="clean">
<ant dir="${basedir}" target="clean"/>
</target>
</project>
and run Ant:
ant -file jenkins-build.xml clean
ant -file jenkins-build.xml build
Thanks to the original author matt

Related

eclipse.buildScript Complete Example Script for headless build

I am trying to generate a build script for a plugin outside the IDE
Below is mybuild.xml
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
<target name="build.plugin">
<antcall target="generateBuildScript" />
<ant dir="${workspace.dir}/${project.name}"
antfile="build.xml"
target="build.update.jar" />
<copy todir="${eclipse.dir}/plugins">
<fileset dir="${workspace.dir}/${project.name}">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="generateBuildScript">
<eclipse.buildScript elements="plugin#${project.name}"
buildDirectory="${workspace.dir}"
baseLocation="${eclipse.dir}"
configInfo="linux,gtk,win32,win32,x86"/>
</target>
</project>
Expecting build.xml to be generated Please Guide me
When I run above script
$java -jar {$Eclipse.Dir}/plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -application org.eclipse.ant.core.antRunner -buildfile <Project_path>\mybuild.xml
I nothing is happening on build success.
Here i have found the answer may help some new bees like me..
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
...
</project>
As there is no default set, it is not generating the required jar file so
modified only the first line as
<project name="com.foo.poo" default="build.plugin" xmlns='antlib:org.apache.tools.ant'>
...
</project>
now the required jar is generated under plugin folder and even copied to plugin folder of eclipse.
baseLocation : Target Plugins Directory absolute path.
buildDirectory: Absolute path to the plugin folder in which the Plugin Project is present.

Unable to deploy JavaFX applicaiton with external libraries in a JAR

I'm developing a JavaFX application in Eclipse. The app has external libraries, like log4j and others and runs perfectly from Eclipse. I've tried deploying it from Eclipse as a Runnable jar through the Eclipse built-in feature, and it runs well on some computers, while on others it would give me an obscure Undefined Link error. After digging around it seems JavaFX needs to be specially packaged either through an ANT script or through the javafxpackager application.
For the life of me I can't seem to deploy a runnable jar through either of those methods. Trying either of those methods, I get an Exception. Things I've tried:
Build the JavaFX application through an ANT script, below is a snippet of the relevant parts of the build script
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<fileset dir="${javafx.sdk.path}/jre/lib" includes="jfxrt.jar"/>
</path>
<target name="compile" depends="clean">
<echo>Compiling the source</echo>
<mkdir dir="${classes.dir}"/>
<!-- Copy over the misc files into the classes dir -->
<copy todir="${classes.dir}/bundles">
<fileset dir="${src.dir}/bundles"/>
</copy>
<copy todir="${classes.dir}/css">
<fileset dir="${src.dir}/css"/>
</copy>
<copy todir="${classes.dir}/img">
<fileset dir="${src.dir}/img"/>
</copy>
<copy todir="${classes.dir}/views">
<fileset dir="${src.dir}/views"/>
</copy>
<copy todir="${classes.dir}/bundles">
<fileset dir="${src.dir}/bundles"/>
</copy>
<copy file="${src.dir}/log4j2.xml" todir="${classes.dir}"/>
<javac target="1.7" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="on">
</javac>
</target>
<target name="jar" depends="compile">
<echo>Creating the main jar file</echo>
<mkdir dir="${distro.dir}" />
<fx:jar destfile="${distro.dir}/main.jar" verbose="true">
<fx:platform javafx="2.1+" j2se="7.0"/>
<fx:application mainClass="${main.class}"/>
<!-- What to include into result jar file?
Everything in the build tree-->
<fileset dir="${classes.dir}"/>
<!-- Define what auxilary resources are needed
These files will go into the manifest file,
where the classpath is defined -->
<fx:resources>
<fx:fileset dir="${distro.dir}" includes="main.jar"/>
<fx:fileset dir="." includes="${lib.dir}/**" type="jar"/>
<fx:fileset dir="." includes="."/>
</fx:resources>
<!-- Make some updates to the Manifest file -->
<manifest>
<attribute name="Implementation-Vendor" value="${app.vendor}"/>
<attribute name="Implementation-Title" value="${app.name}"/>
<attribute name="Class-Path" value="${lib.dir}"/>
<attribute name="Implementation-Version" value="1.0"/>
</manifest>
</fx:jar>
</target>
Compiling/generating the jar through the ant script, I get a window pop up for half a second and "Exception in Application start method" in the console, with no stack trace. I've tried runnning java with the -XX:-OmitStackTraceInFastThrow flag, but it still won't give me a stack trace.
Running through javafxpackager gives the following error:
RenderJob.run: internal exception
java.lang.UnsatisfiedLinkError: com.sun.prism.d3d.D3DContext.nSetBlendEnabled(JZ
Z)I
at com.sun.prism.d3d.D3DContext.nSetBlendEnabled(Native Method)
at com.sun.prism.d3d.D3DContext.initState(D3DContext.java:84)
at com.sun.prism.d3d.D3DResourceFactory.(D3DResourceFactory.java:5
7)
at com.sun.prism.d3d.D3DPipeline.createResourceFactory(D3DPipeline.java:
147)
at com.sun.prism.d3d.D3DPipeline.getD3DResourceFactory(D3DPipeline.java:
153)
at com.sun.prism.d3d.D3DPipeline.findDefaultResourceFactory(D3DPipeline.
java:179)
at com.sun.prism.d3d.D3DPipeline.getDefaultResourceFactory(D3DPipeline.j
ava:201)
at com.sun.prism.GraphicsPipeline.getDefaultResourceFactory(GraphicsPipe
line.java:97)
at com.sun.javafx.tk.quantum.QuantumRenderer$3.run(QuantumRenderer.java:
143)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:47
1)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at com.sun.prism.render.RenderJob.run(RenderJob.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(Quantu
mRenderer.java:98)
at java.lang.Thread.run(Thread.java:724)
You can deploy your application using javafxpackager. If you deploy a self contained application, the Java Runtime Environment will be bundled with your application and it will run on any machine whether the right version of Java is installed or not.
(You should have javafxpackager in your jdk directory under the bin folder.)
Look for your compiled files (.class) in your eclipse workspace folder. They should be in the bin directory.
Create a createjar folder and inside it create a classes and a out folder. Copy all of your .class files in the classes folder. Also include in the classes folder all jar needed by your application.
Now on the command line go inside the createjar directory and run this command :
"C:\path\to\jdk\jdk1.7.0_25\bin\javafxpackager.exe" -createjar -appclass package.MainClass -srcdir classes -outdir out -outfile NameOfYourJar -classpath "" -v
This should create a runnable jar in the out directory. You will need it for the next step.
Now create a deploy folder alongside the createjar folder.
Inside the deploy folder make to other directories dist and packages.
In the dist folder copy your freshly created jar from above plus all the dependencies/ressources it will need.
Go back on the command line (if you ever left it) and go in the deploy directory. Run the following command from there :
"C:\path\to\jdk\jdk1.7.0_25\bin\javafxpackager.exe" -deploy -native -outdir packages -outfile NameOfYourApp -srcdir dist -srcfiles NameOfYourJar.jar -appclass package.MainClass -name "Name of You Application" -title "Title of your application"
Once it is done it should have created all you need to deploy your app including native .exe file to run on Windows platform. This is the self contained application ! To be able to run it you need to go into bundles\NameOfYourApp\app and paste here all dependencies/ressource your app needs.
At last, double click on YourApp.exe and it should run even on machines without Java installed.
With ant files you have two main options: <fx:jar> and <fx:deploy>. The former just produces a jar that allows you to refer to your dependencies if they are in the same file as the jar. You can unpack the jar and look at the MANIFEST file produced to see how they are added to the javafx classpath.
<fx:deploy> allows you to pull in dependencies, but requires that you build a platform-specific installer. It can't be done using a jar. Apparently NetBeans allows you to create a stand-alone jar but I have not tested with that.
you do not package javafxrt.jar with your app
e(fx)clipse would have produced the ant-script for your if you use it

Building Windows 8 Phone App on Command Line

I'm currently porting an existing cross platform framework to Windows Phone 8.
The build process is fully automated and we are using a rock solid CI system.
I can build and deploy Windows Phone 8 samples from Visual Studio (Express 2012),
but now I need to integrate that into our build scripts.
Did anybody ever successfully build (and deploy) a Win Phone 8 app via the commandline?
(Or ant, make, scons, whatever...)
If yes, how?
Any hints are welcome.
I used the following bat file to build WP7 code (+ant automation on top of it). It may be helpful for you.
build.bat
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.xml /t:BuildAndCopy /p:Revision=123
where build.xml is something like (build itself goes under BuildAll target)
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<Major>1</Major>
<Minor>0</Minor>
<Build>0</Build>
<Revision>x</Revision>
<OutputPath>Build\</OutputPath>
<OutputPathDebug>..\Build\Debug\</OutputPathDebug>
<OutputPathRelease>..\Build\</OutputPathRelease>
</PropertyGroup>
<Target Name="BuildAll" DependsOnTargets="Clean; Version">
<msbuild Projects="SomeApp.sln" Properties="Configuration=Release;OutputPath=$(OutputPathRelease)"/>
<msbuild Projects="SomeApp.sln" Properties="Configuration=Debug;OutputPath=$(OutputPathDebug)"/>
</Target>
<Target Name="Clean">
<RemoveDir Directories="$(OutputPath)" Condition="Exists('$(OutputPath)')"/>
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')"/>
</Target>
<Target Name="Version">
<Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
<XmlUpdate
Namespace=""
XmlFileName="WindowsPhone\Properties\WMAppManifest.xml"
XPath="//App[#Version]//#Version"
Value="$(Major).$(Minor).$(Build).$(Revision)"/>
</Target>
<ItemGroup>
<AppFiles Include="$(OutputPath)\**\*.xap"/>
</ItemGroup>
<Target Name="BuildAndCopy" DependsOnTargets="BuildAll">
<Copy
SourceFiles="#(AppFiles)"
DestinationFiles="#(AppFiles->'\\fs\Public\projects\mobile\SomeAppWP\$(Major).$(Minor).$(Build).$(Revision)\%(RecursiveDir)%(Filename)%(Extension)')"
/>
<Copy
SourceFiles="#(AppFiles)"
DestinationFiles="#(AppFiles->'\\fs\Public\projects\mobile\SomeAppWP\latest\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
</Project>
It should be easy. I'll assume you have the following file structure
$/WP8App/SampleApp.sln
You will have to use the paths and solution file in your project. Execute the following instructions, and make sure to update solution file and path:
Open a command prompt
Execute: %VS110COMNTOOLS%vsvars32.bat
Execute: %VS110COMNTOOLS%..\..\VC\WPSDK\WP80\vcvarsphoneall.bat
Execute: MSBuild "WP8App/SampleApp.sln" /t:rebuild
/p:Configuration=Release /p:Platform="Any CPU" /v:d
Please notice:
The computer where you're going to run these commands should have the development environment for WP8 already set up.
If your application uses native libraries (such as PlayerFramework http://playerframework.codeplex.com/ which are installed into VS, these libraries should also be installed before running the commands)
I have used this process on VS2012 Pro and VS2012 Premium and Jenkins as Build Server.
Good luck,
Herb
Thanks to Sergei's MSBuild.exe hint I was able to build a simple sample via the command line.
https://github.com/AndreasOM/wp8-directx-commandline
There is a build.bat included, which should be enough to get you started to build for "windows phone 8" with the build system of your choice.
It's fairly hacky at the moment,
but once I get the current project done
I will clean it up.
Hint:
Never define a "CL" environment variable when working with "CL.exe" ;)

How can I automate compiling a large Java project?

I'm working on an automation project for my employer. We have a pool for each revision of our source code. When you download a revision, you need to create a directory structure with a bunch of third party includes to eventually build the project. I've automated this entire process up to the point of having my script (.bat) compile each particular runnable java application. There are many applications to this single project, and the directory listing looks something like this:
Proj Name
-variousincludesfolder1
-variousincludesfolder2
-variousincludesfolder3
-variousincludesfolder4
-runnableapplicationsandmoreincludes
-con.java
Right now, I'd like to do an automated compiling of con.java, but I don't know where to begin. People have suggested I try Ant, but any automated Ant file generation I get using Eclipse seems only enough to build con.java while an active project file exists. Is there anyway to automate this without using eclipse, to the point of having the batch file generate a .jar itself?
This is definitely a job for Ant. Don't rely on Eclipse-generated Ant files; read through the manual and write one yourself. (You'll likely find out that Ant does things you didn't think of doing in your build script, too.)
To be more specific, here is the documentation for the jar task.
You can define wildcard and pattern matches to include/exclude all sorts of files and folders in your build. Take a look at the Ant manual to see how things like filesets work with include and exclude filters.
Also, read the tutorial.
Here is a simple build file that looks to compile all java files and reference all jars. Place it in the top level directory:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="http://www.ibm.com/developerworks/xml/library/x-antxsl/examples/example2/ant2html.xsl"?>
<project name="Proj Name" default="build" basedir=".">
<property name="src.dir" value="${basedir}" description="base folder where the source files will be found. Typically under /src, but could be anywhere. Defaulting to root directory of the project" />
<property name="build.dir" value="build" description="Where to put build files, separate from src and resource files." />
<path id="master-classpath">
<fileset dir="${basedir}" description="looks for any jar file under the root directory">
<include name="**/*.jar" />
</fileset>
</path>
<target name="build" description="Compile all JAVA files in the project">
<javac srcdir="${src.dir}"
destdir="${build.dir}/classes"
debug="true"
deprecation="true"
verbose="false"
optimize="false"
failonerror="true">
<!--master-classpath is defined above to include any jar files in the project subdirectories(can be customized to include/exclude)-->
<classpath refid="master-classpath"/>
<!--If you want to define a pattern of files/folders to exclude from compilation...-->
<exclude name="**/realm/**"/>
</javac>
</target>
</project>

How can I automate (script) creating a war file in eclipse?

It's 5 button clicks to get eclipse to create a deployable war file for my eclipse project, I figure there's probably some eclipse command line option to do the same thing, so I can just write it into a script, but I'm not seeing it.
Use the Ant war task, set up a relevant build file and you can just hit the "external tools" button to execute it.
You could also setup a Maven build for your web project. Typing mvn package from the command line would then build the project for you.
For integration between Maven and Eclipse, see m2Eclipse and Maven Eclipse Plugin.
I cannot say anything about the WAR packaging itself, sorry.
But as I wrote in
How do I automatically export a WAR after Java build in Eclipse? : If you can describe the WAR packaging with an Ant script, you can have that Ant script being executed automatically after each change to your project. Use Project->Properties->Builders->Add->Ant Builder. Give that builder you custom Ant script and it will automatically be executed after the "normal" builders of your project.
You can even specify in the settings of the builder, if it shall only react on changes to specific files and so on.
The Ant builder is kind of a Swiss army knife for anything you want to automate in the project build without having to use the big tools like maven.
This Ant script should work for standard Dynamic Web Project structure of project:
Create Ant build.xml with replacing of two properties at begining:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Deploy From Eclipse to JBoss" basedir="." default="deploy">
<!-- This replace with yours project name and JBoss location: -->
<property name="warfile" value="MyProject"/>
<property name="deploy" value="/home/honza/jboss-as-7.1.1.Final/standalone/deployments"/>
<target name="create">
<war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
<classes dir="build\classes"/>
<fileset dir="WebContent">
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="copy">
<copy todir="${deploy}" overwrite="true">
<fileset dir=".">
<include name="${warfile}.war"/>
</fileset>
</copy>
</target>
<target name="clear">
<delete includeemptydirs="true">
<fileset dir="${deploy}" defaultexcludes="false">
<include name="${warfile}.*/**" />
</fileset>
</delete>
</target>
<target name="deploy">
<antcall target="create"/>
<antcall target="clear"/>
<antcall target="copy"/>
</target>
</project>
Now should command "ant" do WAR creation and copy them to the JBoss. JBoss automatically deploys wars which finds in deployment directory.
For automatic run after build (Project - Build) add this Buildfile here:
MyProject - Properties - New - Ant builder