I am having a problem producing a working jar file. I would like to end up with a jar file that can run itself by using the command java -jar myjar.jar
So far I have
<project default="jar" name="Create Runnable Jar fecrudbreset">
<target name="clean">
<delete dir="bin"/>
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="./build"/>
<javac srcdir="./src" destdir="./build">
<classpath>
<pathelement location="./lib/sqljdbc4.jar"/>
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="./bin"/>
<jar destfile="./bin/fecrudbreset.jar" >
<manifest>
<attribute name="Main-Class" value="FecruDBreset"/>
<attribute name="Class-Path" value="."/>
<attribute name="Built-By" value="${user.name}"/>
</manifest>
<fileset dir="./build"/>
<zipfileset dir="./lib" includes="sqljdbc4.jar"/>
</jar>
</target>
</project>
The compile works however when I try to run the app I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDataSource
at FecruDBreset.main(Unknown Source)
update:
The main class I have uses the default package. The class is found and starts to run but fails when it cant locate the sql driver it seems. I guess I dont understand why it cant find it.
Here is how the main class is defined:
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;
public class FecruDBreset
{
/*
* Used to reset / nuke fecru database
*/
public static void main(String[] args)
{
Also if I unzip the jar file that is produced the contents look like this:
META-INF/
META-INF/MANIFEST.MF
FecruDBreset.class
sqljdbc4.jar
Update 2: My source tree looks like this:
|-- bin
| `-- fecrudbreset.jar
|-- build
| `-- FecruDBreset.class
|-- build.xml
|-- lib
| `-- sqljdbc4.jar
|-- readme.txt
`-- src
`-- FecruDBreset.java
Anyone have any idea what I am doing wrong? Thanks much in advance.
Chad
The main Jar cannot contain the
sqljdbc4.jar. Instead, a reference to that Jar should be added to the class-path in the manifest.