Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT: Stand alone jar
SWT: Stand alone jar [message #447269] Sat, 11 December 2004 22:22 Go to next message
Eclipse UserFriend
Originally posted by: kelly_stevens81.yahoo.com

I am having some problems creating a stand alone jar using the swt
librarys it seems that it cannot find the main class.

my process is
jar cvfm npreview.jar Manifest.tmp *.class

which creates the npreview.jar file which i can execute using a swing test
program that works.

But when i try to use my npreview.jar file that uses swt and jdbc to
access my access database it creates the jar but throws errors when i try
to execute it.

I want to thank anyone who replys to this in advance and say that i
appreciate all of you who take the time to look at this post.

My thought of what is wrong is that perhaps i dont have an environment
variable set correctly for the swt libraries or that i am not aware of an
include that i must have in my statement.

Manifest.tmp
------------------------------------------
Manifest-Version: 1.0
Main-Class: JDBCApp

This file does have a return at the end.

JDBCApp.java
------------------------------------------------------------ -------------------
//Import statements
import java.sql.*;

import org.eclipse.swt.events.*;

import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.SWT;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

//Main class
public class JDBCApp
{
//Main method
public static void main( String [] args )
{
//Interface call
new JDBCInterface();
}
}

//Database class
class JDBCDatabase
{
//Declarations
String dataSourceName = "db";
String dbURL = "jdbc:odbc:" + dataSourceName;
ResultSet rs;
Statement s;
Connection con;
String[] values = new String[2];
int row = 1;

//Constructor
public JDBCDatabase()
{
//Database connection
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection( dbURL, "", "" );
s = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY );
s.execute( "SELECT * FROM names ORDER BY name_id" );
rs = s.getResultSet();
}
catch( Exception e )
{
System.out.println( "Error: " + e );
}
}

//Name retrieval
void getNames( String d )
{
//Declaration
String direction = d;

try
{
if ( rs != null)
{
//Previous movement
if ( d.equals("prev") )
{
if ( !rs.isFirst() )
{
rs.absolute( --row );
values[0] = rs.getString( "first_name" );
values[1] = rs.getString( "last_name" );
}
else
{
getNames( "first" );
}

}
//Next movement
if ( d.equals("next") )
{
if ( !rs.isLast() )
{
rs.absolute( ++row );
values[0] = rs.getString( "first_name" );
values[1] = rs.getString( "last_name" );
}
else
{
getNames( "last" );
}
}
//First movement
if ( d.equals("first") )
{
row = 1;
rs.first();

values[0] = rs.getString( "first_name" );
values[1] = rs.getString( "last_name" );
}
//Last movement
if ( d.equals("last") )
{
rs.last();
row = rs.getRow();

values[0] = rs.getString( "first_name" );
values[1] = rs.getString( "last_name" );
}
}
}
catch ( Exception e )
{
System.out.println( "Error: " + e );
}
}

//Connection terminator
void closeConnection()
{
try
{
con.close();
s.close();
}
catch ( Exception e )
{
System.out.println( "Error: " + e );
}

}
}

//Interface class
class JDBCInterface
{
Display display = new Display();
Shell shell = new Shell( display );
final Text txtfname = new Text( shell, SWT.BORDER );
final Text txtlname = new Text( shell, SWT.BORDER );
JDBCDatabase db = new JDBCDatabase();

//Constructor
public JDBCInterface()
{InterfaceSetup();}

public void loadName( String d )
{


String last, first;
String[] values;
values = new String[2];

db.getNames( d );
first = db.values[0];
last = db.values[1];
txtlname.setText( last );
txtfname.setText( first );
}

//Interface method
public void InterfaceSetup()
{
loadName( "first" );
FormLayout flayout = new FormLayout();
flayout.marginHeight = 5;
flayout.marginWidth = 5;
shell.setLayout( flayout );
shell.setText( "Name Previewer" );

//Lblfname setup
FormData fdata = new FormData();
fdata.top = new FormAttachment( 0, 7 );
fdata.left = new FormAttachment( 0, 5 );
Label lblfname = new Label( shell, SWT.NONE );
lblfname.setText( "First Name" );
lblfname.setLayoutData( fdata );

//Txtfname setup
fdata = new FormData();
fdata.top = new FormAttachment( 0, 5 );
fdata.left = new FormAttachment( lblfname, 5, SWT.RIGHT );
fdata.right = new FormAttachment( 100, -5 );
txtfname.setLayoutData( fdata );

//Lbllname setup
fdata = new FormData();
fdata.top = new FormAttachment( lblfname, 12 );
fdata.left = new FormAttachment( 0, 5 );
Label lbllname = new Label( shell, SWT.NONE );
lbllname.setText( "Last Name" );
lbllname.setLayoutData( fdata );

//Txtlname setup
fdata = new FormData();
fdata.top = new FormAttachment( txtfname, 5 );
fdata.left = new FormAttachment( lbllname, 5, SWT.RIGHT );
fdata.right = new FormAttachment( 100, -5 );
txtlname.setLayoutData( fdata );

//Btnfirst setup
fdata = new FormData();
fdata.top = new FormAttachment( lbllname, 10 );
fdata.left = new FormAttachment( 0, 5 );
fdata.right = new FormAttachment( 25, -5 );
Button btnfirst = new Button( shell, SWT.PUSH );
btnfirst.setText( "<<" );
btnfirst.setLayoutData( fdata );
btnfirst.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
loadName( "first" );
}
});

//Btnprev setup
fdata = new FormData();
fdata.top = new FormAttachment( lbllname, 10 );
fdata.left = new FormAttachment( btnfirst, 5, SWT.RIGHT );
fdata.right = new FormAttachment( 50, -5 );
Button btnprev = new Button( shell, SWT.PUSH );
btnprev.setText( "<" );
btnprev.setLayoutData( fdata );
btnprev.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
loadName( "prev" );
}
});

//Btnnext setup
fdata = new FormData();
fdata.top = new FormAttachment( lbllname, 10 );
fdata.left = new FormAttachment( btnprev, 5, SWT.RIGHT );
fdata.right = new FormAttachment( 75, -5 );
Button btnnext = new Button( shell, SWT.PUSH );
btnnext.setText( ">" );
btnnext.setLayoutData( fdata );
btnnext.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
loadName( "next" );
}
});

//Btnlast setup
fdata = new FormData();
fdata.top = new FormAttachment( lbllname, 10 );
fdata.left = new FormAttachment( btnnext, 5, SWT.RIGHT );
fdata.right = new FormAttachment( 100, -5 );
Button btnlast = new Button( shell, SWT.PUSH );
btnlast.setText( ">>" );
btnlast.setLayoutData( fdata );
btnlast.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
{
loadName( "last" );
}
});

//Show the shell
shell.pack();
shell.open();

//Resource Mangement
while ( !shell.isDisposed() )
{
if ( !display.readAndDispatch() )
{
display.sleep();
}
}
db.closeConnection();
display.dispose();
}
}
Re: Stand alone jar [message #447270 is a reply to message #447269] Sun, 12 December 2004 01:10 Go to previous messageGo to next message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Hi Kelly,

I have compiled and jared your classes (almost) without any problems (&
without any extra environment variables, I just inlcuded the path to
javac.exe (j2sdk\bin) ).
The npreview.jar I compiled finds the main class and runs without problems
(Of course, I get an SQL exception because I don't have the JDBC:ODBC data
source available...)

Provided that the file DOES have a new line at the end, your manifest seems
to be perfectly valid.

Double check this by unpacking your npreview.jar and looking at
/META-INF/MANIFEST.MF
If you can see your instructions in that manifest (Main-Class: JDBCApp),
java.exe should not have any problems. If you see an empty manifest (wich
only contains Created-By and/or Manifest-Version), my best bet is that there
IS NO return at the end!

Try adding several new lines at the end of the file just to make sure (they
will be trimmed away by jar.exe anyways) and making a new jar (or updating
your jar using: jar -uvfm npreview.jar Manifest.tmp)

You might also want to add
Class-Path: swt.jar
to your manifest, if this is stand alone application (be sure to put swt.jar
and the native library in the same directory as the jar file)

I have also allowed myself to attach the manifest file and the working
npreview.jar to this email for you....

regards,

Mani Ghamari

"kelly stevens" <kelly_stevens81@yahoo.com> wrote in message
news:cpfrud$40e$1@www.eclipse.org...
>I am having some problems creating a stand alone jar using the swt
> librarys it seems that it cannot find the main class.
>
> my process is
> jar cvfm npreview.jar Manifest.tmp *.class
>
> which creates the npreview.jar file which i can execute using a swing test
> program that works.
>
> But when i try to use my npreview.jar file that uses swt and jdbc to
> access my access database it creates the jar but throws errors when i try
> to execute it.
>
> I want to thank anyone who replys to this in advance and say that i
> appreciate all of you who take the time to look at this post.
>
> My thought of what is wrong is that perhaps i dont have an environment
> variable set correctly for the swt libraries or that i am not aware of an
> include that i must have in my statement.
>
> Manifest.tmp
> ------------------------------------------
> Manifest-Version: 1.0
> Main-Class: JDBCApp
>
> This file does have a return at the end.
>
> JDBCApp.java
> ------------------------------------------------------------ -------------------
> //Import statements
> import java.sql.*;
>
> import org.eclipse.swt.events.*;
>
> import org.eclipse.swt.layout.FormAttachment;
> import org.eclipse.swt.layout.FormData;
> import org.eclipse.swt.layout.FormLayout;
> import org.eclipse.swt.layout.GridLayout;
>
> import org.eclipse.swt.SWT;
>
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> //Main class
> public class JDBCApp
> {
> //Main method
> public static void main( String [] args )
> {
> //Interface call
> new JDBCInterface();
> }
> }
>
> //Database class
> class JDBCDatabase
> {
> //Declarations
> String dataSourceName = "db";
> String dbURL = "jdbc:odbc:" + dataSourceName;
> ResultSet rs;
> Statement s;
> Connection con;
> String[] values = new String[2];
> int row = 1;
>
> //Constructor
> public JDBCDatabase()
> {
> //Database connection
> try
> {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> con = DriverManager.getConnection( dbURL, "", "" );
> s = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
> ResultSet.CONCUR_READ_ONLY );
> s.execute( "SELECT * FROM names ORDER BY name_id" );
> rs = s.getResultSet();
> }
> catch( Exception e )
> {
> System.out.println( "Error: " + e );
> }
> }
>
> //Name retrieval
> void getNames( String d )
> {
> //Declaration
> String direction = d;
>
> try
> {
> if ( rs != null)
> {
> //Previous movement
> if ( d.equals("prev") )
> {
> if ( !rs.isFirst() )
> {
> rs.absolute( --row );
> values[0] = rs.getString( "first_name" );
> values[1] = rs.getString( "last_name" );
> }
> else
> {
> getNames( "first" );
> }
>
> }
> //Next movement
> if ( d.equals("next") )
> {
> if ( !rs.isLast() )
> {
> rs.absolute( ++row );
> values[0] = rs.getString( "first_name" );
> values[1] = rs.getString( "last_name" );
> }
> else
> {
> getNames( "last" );
> }
> }
> //First movement
> if ( d.equals("first") )
> {
> row = 1;
> rs.first();
>
> values[0] = rs.getString( "first_name" );
> values[1] = rs.getString( "last_name" );
> }
> //Last movement
> if ( d.equals("last") )
> {
> rs.last();
> row = rs.getRow();
>
> values[0] = rs.getString( "first_name" );
> values[1] = rs.getString( "last_name" );
> }
> }
> }
> catch ( Exception e )
> {
> System.out.println( "Error: " + e );
> }
> }
>
> //Connection terminator
> void closeConnection()
> {
> try
> {
> con.close();
> s.close();
> }
> catch ( Exception e )
> {
> System.out.println( "Error: " + e );
> }
>
> }
> }
>
> //Interface class
> class JDBCInterface
> {
> Display display = new Display();
> Shell shell = new Shell( display );
> final Text txtfname = new Text( shell, SWT.BORDER );
> final Text txtlname = new Text( shell, SWT.BORDER );
> JDBCDatabase db = new JDBCDatabase();
>
> //Constructor
> public JDBCInterface()
> {InterfaceSetup();}
>
> public void loadName( String d )
> {
>
>
> String last, first;
> String[] values;
> values = new String[2];
>
> db.getNames( d );
> first = db.values[0];
> last = db.values[1];
> txtlname.setText( last );
> txtfname.setText( first );
> }
>
> //Interface method
> public void InterfaceSetup()
> {
> loadName( "first" );
> FormLayout flayout = new FormLayout();
> flayout.marginHeight = 5;
> flayout.marginWidth = 5;
> shell.setLayout( flayout );
> shell.setText( "Name Previewer" );
>
> //Lblfname setup
> FormData fdata = new FormData();
> fdata.top = new FormAttachment( 0, 7 );
> fdata.left = new FormAttachment( 0, 5 );
> Label lblfname = new Label( shell, SWT.NONE );
> lblfname.setText( "First Name" );
> lblfname.setLayoutData( fdata );
>
> //Txtfname setup
> fdata = new FormData();
> fdata.top = new FormAttachment( 0, 5 );
> fdata.left = new FormAttachment( lblfname, 5, SWT.RIGHT );
> fdata.right = new FormAttachment( 100, -5 );
> txtfname.setLayoutData( fdata );
>
> //Lbllname setup
> fdata = new FormData();
> fdata.top = new FormAttachment( lblfname, 12 );
> fdata.left = new FormAttachment( 0, 5 );
> Label lbllname = new Label( shell, SWT.NONE );
> lbllname.setText( "Last Name" );
> lbllname.setLayoutData( fdata );
>
> //Txtlname setup
> fdata = new FormData();
> fdata.top = new FormAttachment( txtfname, 5 );
> fdata.left = new FormAttachment( lbllname, 5, SWT.RIGHT );
> fdata.right = new FormAttachment( 100, -5 );
> txtlname.setLayoutData( fdata );
>
> //Btnfirst setup
> fdata = new FormData();
> fdata.top = new FormAttachment( lbllname, 10 );
> fdata.left = new FormAttachment( 0, 5 );
> fdata.right = new FormAttachment( 25, -5 );
> Button btnfirst = new Button( shell, SWT.PUSH );
> btnfirst.setText( "<<" );
> btnfirst.setLayoutData( fdata );
> btnfirst.addSelectionListener( new SelectionAdapter()
> {
> public void widgetSelected( SelectionEvent event )
> {
> loadName( "first" );
> }
> });
>
> //Btnprev setup
> fdata = new FormData();
> fdata.top = new FormAttachment( lbllname, 10 );
> fdata.left = new FormAttachment( btnfirst, 5, SWT.RIGHT );
> fdata.right = new FormAttachment( 50, -5 );
> Button btnprev = new Button( shell, SWT.PUSH );
> btnprev.setText( "<" );
> btnprev.setLayoutData( fdata );
> btnprev.addSelectionListener( new SelectionAdapter()
> {
> public void widgetSelected( SelectionEvent event )
> {
> loadName( "prev" );
> }
> });
>
> //Btnnext setup
> fdata = new FormData();
> fdata.top = new FormAttachment( lbllname, 10 );
> fdata.left = new FormAttachment( btnprev, 5, SWT.RIGHT );
> fdata.right = new FormAttachment( 75, -5 );
> Button btnnext = new Button( shell, SWT.PUSH );
> btnnext.setText( ">" );
> btnnext.setLayoutData( fdata );
> btnnext.addSelectionListener( new SelectionAdapter()
> {
> public void widgetSelected( SelectionEvent event )
> {
> loadName( "next" );
> }
> });
>
> //Btnlast setup
> fdata = new FormData();
> fdata.top = new FormAttachment( lbllname, 10 );
> fdata.left = new FormAttachment( btnnext, 5, SWT.RIGHT );
> fdata.right = new FormAttachment( 100, -5 );
> Button btnlast = new Button( shell, SWT.PUSH );
> btnlast.setText( ">>" );
> btnlast.setLayoutData( fdata );
> btnlast.addSelectionListener( new SelectionAdapter()
> {
> public void widgetSelected( SelectionEvent event )
> {
> loadName( "last" );
> }
> });
>
> //Show the shell
> shell.pack();
> shell.open();
>
> //Resource Mangement
> while ( !shell.isDisposed() )
> {
> if ( !display.readAndDispatch() )
> {
> display.sleep();
> }
> }
> db.closeConnection();
> display.dispose();
> }
> }
>
>
>



  • Attachment: npreview.jar
    (Size: 5.86KB, Downloaded 130 times)
  • Attachment: Manifest.tmp
    (Size: 0.07KB, Downloaded 145 times)
Re: Stand alone jar [message #447274 is a reply to message #447270] Sun, 12 December 2004 23:27 Go to previous message
Eclipse UserFriend
Originally posted by: kelly_stevens81.yahoo.com

Mani Ghamari wrote:


Thank you Mani i put in the line Class-Path: swt.jar into my manifest.tmp
file and moved a copy of swt.jar into the directory now everything works
fine.
Previous Topic:Eclipse Forms for stand alone SWT application
Next Topic:GUI hanging.
Goto Forum:
  


Current Time: Thu Apr 25 10:23:39 GMT 2024

Powered by FUDForum. Page generated in 0.03229 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top