Reputation: 6980
I have a Netbeans project that has a source folder (outside the Netbeans project folder). Now, When I compile the source code from the IDE, everything works fine. But, when I use my own build script it gives an error at runtime.
The application depends on several external libraries that I specify using the path
element and the corresponding refid
attribute in classpath
tag (see code below)
Here is my buildfile
<project name="XX" default="dist" basedir=".">
<property name="dir.src" location="E:/XX git/xx/src"/>
<property name="nbproj" location="E:/Netbeans Project"/>
<property name="dir.dist" value="dist"/>
<path id="libs">
<fileset dir="${nbproj}/dist/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="dist"/>
<delete dir="release"/>
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="${dir.src}" destdir="build/classes" includeantruntime="false">
<classpath refid="libs"/>
</javac>
</target>
</project>
When I compile it using ant compile
, it compiles all the source files without any error. But, when I execute it using the command
java -cp "E:\Netbeans Project\dist\lib\*;." controller.CZSaw
it creates the application GUI nicely and then when I perform some action, it fails with the following error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at controller.viewsynchronizer.CZViewManager.getIcon(Unknown Source)
at view.script.CZScriptView.<init>(Unknown Source)
at controller.script.CZScriptProcessor.<init>(Unknown Source)
at controller.script.CZScriptProcessor.getInstance(Unknown Source)
...
I know it would be difficult to point out some error looking just at the source code. But, as the same code compiled and worked nicely from the IDE, I think there is something wrong with the way I am compiling. Is there any apparent mistake in the buildfile.
Let me know if I missed some useful information here.
Upvotes: 0
Views: 145
Reputation: 309018
Classic mistake: assuming that because "everything worked fine" in one setting means that you've done everything right and are blameless for anything that subsequently goes wrong.
It means that your IDE took care of some things that you're ignorant of.
Look at the first class that's yours:
controller.viewsynchronizer.CZViewManager.getIcon(Unknown Source)
It looks like your controller is looking for an icon image that's not in the CLASSPATH.
Upvotes: 1