Results 1 to 4 of 4
  1. #1
    javawala is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Question Run SWT application from executable jar built by maven and source codes in eclipse

    Hi, I'm new java.

    I'm trying a SWT Stand-alone (desktop) application.

    My environment is OS: windows XP 23 bits

    JDK version : JDK1.7.0_45 installed under C:\Program Files\Java
    Eclipse 4.3 (Kepler) : In C:\eclipse
    Eclipse workspace : E:\workspace
    Eclipse Project : E:\workspace\SWTGroupLogin
    Package : E:\workspace\SWTGroupLogin\mypackage
    Maven 3.2.1 : in E:\maven-3.2.1
    Maven Project Folder : E:\MavenProjects\SWTL
    Maven local repository : in E:\MavenLocalRepo
    MyExecutable jar : SWTGroupLogin-1.0-SNAPSHOT.jar
    Test-Exection : Under C:\AA the executable jar has been renamed to AX.jar
    Native DLL swt-win32-4332.dll : copied from C:\Documents and Settings\WinUser\.swt\lib\win32\x86 and pasted into
    Run Library FOlder : C:\AA\RefLib contains
    swt-win32-4332.dll; also copied to C:\Windows\System32, C:\C:\Program Files\Java\JDK1.7.0_u45\bin, the executable-jar-folder C:\AA
    swt.jar
    org.eclipse.swt.win32.win32.x86-4.3.jar



    I've attached the source files, pom.xml files

    The file App.java has a non functional method; Fully commented

    The source files have been copied from E:\worspace\SWTGroupLogin\src\mypackage and pasted to E:\MavenProjects\SWTL\src\main\java\mypackage prior to maven build.

    my maven build command at the foderE:\MavenProjects\SWTL was

    mvn clean compiler:compile package



    The application is not bound to database as of now. It is a mock project intended only for testing the integration of techniques and tools before I start developing any real

    application.
    I can run my application from within eclipse IDE by rightclick -> Run As -> java application.

    I then build and package to create an executable jar with the manifest.mf using maven without any error.

    My Manifest.mf has

    Manifest-Version: 1.0
    Built-By: WinUser
    Build-Jdk: 1.7.0_45
    Class-Path: .\RefLib\swt.jar .\RefLib\org.eclipse.swt.win32.win32.x86-4.3.jar
    Created-By: Apache Maven 3.2.1
    Main-Class: mypackage.TestSWTGroupLogin
    Archiver-Version: Plexus Archiver



    But when I try to run using from command line using from the application directory C:\AA

    java -classpath .\RefLib;.\Reflib\swt.jar;.\RefLib\org.eclipse.swt .win32.win32.x86-4.3.jar -Djava.library.path=. -jar AX.jar

    I get Exception in thread "main" java.lang.ClassNotFoundException org/eclipse/swt/widgets/layout AT mypackage.TestSWTGrouplogin.java:14>
    caused by java.lang.ClassNotFoundException:org.eclipse.swt.w idgets
    ...

    My TestSWTGroupLogin has

    package mypackage;

    public class TestSWTGroupLogin {

    public TestSWTGroupLogin() {
    // TODO Auto-generated constructor stub
    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    SWTGroupLogin gl = new SWTGroupLogin();
    }

    }


    Follwing is the content of SWTGroupLogin.java in mypackages

    package mypackage;


    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.events.*;




    import org.eclipse.swt.graphics.*;
    import org.eclipse.swt.widgets.Group;


    public class SWTGroupLogin {
    Display display = new Display();
    Shell shell = new Shell(display, SWT.CLOSE |SWT.APPLICATION_MODAL );



    public SWTGroupLogin() {
    // TODO Auto-generated constructor stub


    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);
    shell.setText("Group-Login");
    Label lblGroup=new Label(shell, SWT.NULL );
    lblGroup.setText("Group");
    Combo cboGroup = new Combo(shell, SWT.READ_ONLY);

    cboGroup.setBackground(display.getSystemColor(SWT. COLOR_DARK_CYAN));
    cboGroup.setForeground(display.getSystemColor(SWT. COLOR_YELLOW));

    Label lblUname=new Label(shell, SWT.NONE );
    lblUname.setText("Username");
    Text txtUname = new Text(shell, SWT.SINGLE| SWT.BORDER );
    txtUname.setText("");
    txtUname.setTextLimit(20);
    Label lblPwd=new Label(shell, SWT.NONE );
    lblPwd.setText("Password");
    Text txtPwd =new Text(shell, SWT.FLAT|SWT.SINGLE | SWT.BORDER);


    txtPwd.setEchoChar('*');
    txtPwd.setTextLimit(20);
    Button btnLogin = new Button(shell, SWT.PUSH);
    btnLogin.setText("Login");
    btnLogin.setSize(400, 300);
    Button btnCancel = new Button(shell, SWT.PUSH);
    btnCancel.setText("Cancel");

    shell.open();


    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    display.dispose();
    }

    }



    POM.xml at E:\MavenProjects\SWTL contains

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tei</groupId>
    <artifactId>SWTGroupLogin</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>SWTGroupLogin</name>
    <url>http://maven.apache.org</url>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
    <optional>true</optional>
    </dependency>

    <dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-core</artifactId>
    <version>1.3</version>
    <scope>test</scope>
    </dependency>

    <!-- SWT Lib Ref -->
    <dependency>
    <groupId>swt</groupId>
    <artifactId>swtjar</artifactId>
    <scope>system</scope>
    <version>4.3</version>
    <systemPath>${basedir}\src\RefLib\swt.jar</systemPath>
    </dependency>


    <dependency>
    <groupId>swt</groupId>
    <artifactId>org.eclipse.swt.win32.win32.x86-4.3.jar</artifactId>
    <scope>system</scope>
    <version>4.3</version>
    <systemPath>${basedir}\src\RefLib\org.eclipse.swt. win32.win32.x86-4.3.jar</systemPath>
    </dependency>
    </dependencies>
    <build>
    <!-- <sourceDirectory>src</sourceDirectory> -->
    <plugins>
    <!-- For Compilation -->
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
    <source>1.7</source>
    <target>1.7</target>
    <fork>true</fork>
    <executables>C:\Program Files\Java\jdk1.7.0_45\bin</executables>
    </configuration>
    </plugin>

    <!-- for JUNIT Test -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>

    <dependencies>
    <dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-junit47</artifactId>
    <version>2.17</version>
    </dependency>
    </dependencies>

    </plugin>


    <!-- FOR BULIDING SINGLE EXECUTABLE JAR with MANIFEST in packageing phase with command "mvn package" -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
    <archive>
    <!--
    <manifestFile>
    ${project.build.outputDirectory}/META-INF/MANIFEST.MF
    </manifestFile>
    -->

    <manifest>
    <addClasspath>true</addClasspath>
    <mainClass>mypackage.TestSWTGroupLogin</mainClass>
    <!-- <classpathPrefix>dependency-jars/</classpathPrefix> -->
    <!-- <classpathPrefix>RefLib/</classpathPrefix> -->

    </manifest>
    <manifestEntries>
    <Class-Path>RefLib</Class-Path>
    </manifestEntries>
    </archive>
    </configuration>
    </plugin>

    <!-- For Adding Project DEPENDENCY CLASSPATH : START FROM HERE -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.5.1</version>
    <executions>
    <execution>
    <id>copy-dependencies</id>
    <phase>package</phase>
    <goals>
    <goal>copy-dependencies</goal>
    </goals>
    <configuration>
    <outputDirectory>
    ${project.build.directory}/dependency-jars/
    </outputDirectory>
    </configuration>
    </execution>
    </executions>
    </plugin>
    <!-- For Adding Project DEPENDENCY CLASSPATH : END HERE -->

    </plugins>
    </build>
    </project>



    Already spent four days and tried soooo many google findings, but to no avail. Please help. I'm sure this whole life cycle whas been faced by many newbies, and I am anticipating to hear about solution very soon.

    Thanks in advance.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,002
    Rep Power
    6

    Default Re: Run SWT application from executable jar built by maven and source codes in eclips

    Well its an executable jar so that classpath you're passing to java is entirely ignored; you can stop doing that. The classpath must be set in a class-path line inside the manifest. And it is present if I believe what you posted. The question is: where are those jars referenced there? The classpath forces the jars to be present in a directory 'RefLib' in the directory where you are invoking the jar, which probably means you have a directory structure that looks like this:

    RefLib\swt.jar
    RefLib\org.eclipse.swt.win32.win32.x86-4.3.jar
    AX.jar

    Is this the case?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    javawala is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Run SWT application from executable jar built by maven and source codes in eclips

    Many Tahnks gimbal2 for taking your valued effort to help me out.

    My application jar is C:\AA\AX.jar
    I have following three files Both In C:\AA\RefLib and C:\AA as well, even before posting the issue. But still no luck.
    swt.jar
    org.eclipse.swt.win32.win32.x86-4.3.jar
    swt-win32-4332.dll

    I'm just clueless. Please help.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,002
    Rep Power
    6

    Default Re: Run SWT application from executable jar built by maven and source codes in eclips

    I can't really say anything more to be honest. It all "looks" okay to me. There are a few things I would experiment with changing myself, such as renaming that oddly named swt jar to something a lot shorter and to alter the manifest.mf file so the Class-Path line has clean relative paths like "path/to/file.jar" in stead of "./path/to/file.jar".

    I would also skip the -Djava.library.path= since the DLL is in the same directory of the jar anyway; the current working directory is on the OS binary search path by default.


    PS: you're sure you've got all the necessary SWT jars right? I've been assuming that this is the case so far because I assume you are working from proper documentation and not just trying stuff you found in some random internet page.
    Last edited by gimbal2; 04-02-2014 at 09:35 AM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 1
    Last Post: 09-03-2013, 12:54 PM
  2. Need tips on how to read long source codes
    By Kagiso in forum New To Java
    Replies: 2
    Last Post: 05-21-2013, 11:36 AM
  3. creating executable with maven
    By GlWy in forum Advanced Java
    Replies: 2
    Last Post: 01-24-2011, 09:20 AM
  4. import source codes into nbproject
    By bassfero in forum NetBeans
    Replies: 8
    Last Post: 01-12-2011, 09:58 AM
  5. Replies: 0
    Last Post: 04-20-2009, 06:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •