Build the java project using build.xml in Netbeans - java

When I try to do Clean and Build project in Netbeans for the project Jsignpdf I get below error. But If I debug the project it runs without error as I have included all the required libraries. I have limited knowledge of java and it is the first project I am trying to build.
ant -f "C:\\Documents and Settings\\user\\My Documents\\NetBeansProjects\\jsignpdf-master" clean jar
clean:
Cleaning build
C:\Documents and Settings\user\My Documents\NetBeansProjects\jsignpdf-master\build.xml:47: The following error occurred while executing this line:
C:\Documents and Settings\user\My Documents\NetBeansProjects\jsignpdf-itxt\src\build.xml:10: taskdef class net.sourceforge.jarbundler.JarBundler cannot be found
using the classloader AntClassLoader[]
BUILD FAILED (total time: 0 seconds)
As seen in this error message i clicked on the first build.xml link and it was pointing out below portion(target name="clean")
<target name="clean">
<echo message="Cleaning build" />
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${output.dir}"/>
<ant antfile="../jsignpdf-itxt/src/build.xml" useNativeBasedir="true" target="clean" />
</target>
When i clicked on second build.xml link mentioned in error i got below portion of xml highlighted.
<taskdef name="jarbundler" classname="net.sourceforge.jarbundler.JarBundler">
<classpath>
<pathelement location="${jarbundler.jar}"/>
</classpath>
</taskdef>
Actually i was getting lot of errors and solved them. There was also error like JarBundler not found.then I downloaded it from this link.It had .java files,not class files. So I created a package as relevant like net.sourceforge.jarbundler and placed the files which required. After doing all these I am still getting errors while building as described above. I googled a lot for building java app, build xml, ants etc etc and not able to resolve the errors after from last two days. Now my only hope is to some one help me on this error.For more information please download the project.

Related

Netbeans, Ant and nesting build directories

I am having a problem with an Ant project in Netbeans 7.4 . When building a certain web app that i had to create via importing it from a WAR into Netbeans it keeps nesting the output directories in the build directory deeper and deeper.
It happens during the Ant target -copy-webdir . It outputs "x.class omitted as pathtox/x.class" for every file in the build/web directory and creates an even deeper nested set of directories on each build.
Here is a small extract from the project.properties file:
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
target -copy-webdir in the nbproject/build-impl.xml:
<target name="-copy-webdir">
<copy todir="${build.web.dir}">
<fileset dir="${web.docbase.dir}" excludes="${build.web.excludes},${excludes}" includes="${includes}"/>
</copy>
<copy todir="${build.web.dir}/WEB-INF">
<fileset dir="${webinf.dir}" excludes="${build.web.excludes}"/>
</copy>
</target>
What am i doing wrong here?

Ant build using two projects

I have two separate projects inside of eclipse: "project" and "pinclude"
Project includes pinclude, so without somehow include the java files for that project inside of my build.xml, javac will always return errors.
How do I got about including .class files inside of ant/javac? I've tried searching for a solution, but so far I've only came up with ways of adding jar files. Would creating a jar of all the "pinclude" .class files fix my problem?.
Thank you for your help.
NOTE:
I'm sorry for the poor naming convention; These are just projects I made to figure out this problem out.
Also, please ignore srcdir and destdit, they are not important.
Build.xml
<project name="project" basedir="." default="dist" >
<target name="dist" >
<javac destdir="bin"
srcdir="${basedir}\myfileslocation\" >
</javac>
</target>
How do I got about including .class files inside of ant/javac? I've
tried searching for a solution, but so far I've only came up with ways
of adding jar files. Would creating a jar of all the "pinclude" .class
files fix my problem?.
Yes. It helps to separate functionality into smaller modules. If you export one project (pinclude in this case) into a jar and import(via classpath) in another , that is the most correct step.
I'm not 100% sure what you need. Are you saying that you have class files from pininclude, and you need to include them in your <javac> compile task? It would be something like this:
<javac destdir="bin"
srcdir="${basedir}/myfileslocation">
<classpath>
<pathelement path="${path.to.pininclude.javac.files}"/>
</classpath>
</javac>

How do I load optional task sshexec into Ant in a no-configuration manner?

I am using sshexec, which depends on jsch-0.1.48.jar. I can't just put that into the ant/lib directory because other users wishing to use the same build script will have to make a configuration on their machine before they can do so.
What I want to do is to be able to reference jsch-0.1.48.jar as part of the project. Currently, I have it sitting in project/libs directory and I am trying something like:
<property name="lib" location="lib"/>
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec">
<classpath>
<pathelement location="${lib}/jsch-0.1.48.jar"/>
</classpath>
</taskdef>
<target name="sshcmd" description="ssh command">
<sshexec host="X.X.X.X" username="USER" password="PASS" command="cmd" trust="true"/>
</target>
But that's not working:
C:\dev\trunk\project:>ant sshcmd
Buildfile: C:\dev\trunk\project\build.xml
BUILD FAILED
C:\dev\trunk\project\build.xml:275: taskdef A class needed by class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec cannot be found: com/jcraft/jsch/Logger
using the classloader AntClassLoader[C:\dev\trunk\project\lib\jsch-0.1.48.jar]
Total time: 0 seconds
The sshexec task is built into ANT, you do not need to invoke a taskdef operation to use it. All that's missing is the jsch jar.
This can installed using a bootstrap target as follows (from Maven Central):
<target name="bootstrap" description="Install missing jars">
<mkdir dir="${user.home}/.ant/lib"/>
<get src="http://search.maven.org/remotecontent?filepath=com/jcraft/jsch/0.1.48/jsch-0.1.48.jar" dest="${user.home}/.ant/lib/jsch.jar"/>
</target>
This target only needs to be run once, after which the ANT sshexec task will work as expected on the developer's PC.
Update
If you don't want to download jars another mechanism to pass the location of ANT libraries from the command line as follows:
ant -lib /path/to/project/lib/dir ...
For more details on ANT library management, I refer you to the ANT manual
The jsch jar is packaged with my project. So instead of downloading it, I am copying it into the ant library. The build will fail the first time it is run, which is fine for my purposes. It will succeed the second time because the jar will be in the library and would be loaded at start.
<target name="jschset" description="Set the jar">
<copy file="${lib}/jsch-0.1.48.jar" tofile="${ant.home}/lib/jsch-0.1.48.jar"/>
</target>

Ant scripting creating 2 class files

I am not sure If I am asking a very simple question but I have a project in which the developer has used "XSD" files to create java source codes. The input to the project is an XML message which will be parsed into java object.
The project is working fine if I export the class files into a jar file (using eclipse options to export class files into jar files).
But if I use "ant" script to compile and create a jar file, I always get "JAXBException". After Checking I found that the main java file is compiled into 2 class files by ant script, whereas when I use eclipse to compile there is only one class file.
For example -
Main Java file - MpgProcessor.java
Compile using eclipse - MpgProcessor.class
Compile using ant - MpgProcessor.class and MpgProcessor$1.class.
I am using following command in ant to compile the java files -
<target name="compile" depends="clean-build-files" >
<echo message="STEP 2 = COMPILING JAVA FILES " />
<mkdir dir="${classDir}" description="Ensure launch directory created" />
<javac srcdir="${src.dir}" destdir="${classDir}" classpathref="build.classpath" debug="on" compiler="javac1.6"/>
<javac srcdir="${src.generated}" destdir="${classDir}" classpathref="build.classpath" debug="on" compiler="javac1.6" verbose="off"/>
</target>
Can anyone please help?

Java: How to compile a runnable jar from packages?

My Java application has got a package structure similar to this:
src/com/name/app
src/com/name/app/do
src/com/name/utils/db
How would I go about compiling Java files in these directories in to a runnable jar? I need to package required libraries into the generated JAR (jdbc).
I've always done these things in Eclipse but now I need to supply a couple of people with a way to compile the repository without the use of eclipse and I was thinking of making a makefile or a script that invokes the necessary javac pattern.
Take a look at Ant. It's a relatively simple build tool to understand, and provides everything that meets your requirements. Here's a quick skeleton build.xml to get you started:
<project name="my_app_name" default="jar">
<target name="compile">
<javac srcdir="src" destdir="bin">
<classpath>
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar">
<jar manifest="manifest_file" destfile="dist/my_app_name.jar">
<fileset dir="bin" />
<fileset dir="lib" />
</jar>
</target>
You need to create a manifest file that will tell the java process which class holds the "main" method. Here is a good place to start learning about manifests.
As an alternate that produces really cluttered Ant build files, you can right click on your Eclipse project and choose "Export...", then choose "General > Ant Buildfiles".
Anyway, that should get you started. You can ask more specific questions as you run into them.
First of all, consider using Ant for such a task.
But since you asked for a manual process, you need to first create a manifest file, like so:
Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Class-Path: lib/jdbc.jar lib/otherlib.jar
Main-Class: com.name.app.MainClass
Replace the contents of Class-Path with your libs, and Main-Class with the fully qualified name of your main class.
Then, you need to generate the actual .jar, using the following command:
jar cfm app.jar MANIFEST.MF src/com/name/app/*.class src/com/name/app/do/*.class
Where MANIFEST.MF is the previously mentioned manifest file, and the rest is the folders where your .java classes lie in.
Finally, to run your app, you simply execute: java -jar app.jar.
Consider using Ant to do this. http://ant.apache.org/
I recommend that you use Apache Ant to implement your build scripts.
If implemented correctly, Ant is easy to use and the build scripts can be run on any platform that you can install a JDK on. Indeed, with a little bit of work, you can even set up your project so that users don't even need to download / install Ant. (Hint: add the Ant JAR files and a wrapper script to your project distro)

Categories