FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Tools
(Moderator: REAS)
   creating an EXE
« Previous topic | Next topic »

Pages: 1 2 
   Author  Topic: creating an EXE  (Read 12758 times)
guybowden


creating an EXE
« on: May 11th, 2004, 11:09am »

Hi,
 
I'm developing some real time video effects in P5 and need to create an executable file for distribution / ease of install etc.
 
The app uses the video feed from an attached webcam.
 
Is there a way I can compile the code into an Exe?
 
thanks
Guy
 
amoeba

WWW
Re: creating an EXE
« Reply #1 on: May 11th, 2004, 3:57pm »

Processing does not have a way of exporting stand-alone .exe files as of now. On a Windows platform you have basically two options:  
 
1. You can use a .bat file to launch the JAR file from the command-line using Sun's JRE.
 
2. You can import your project into a full Java tool like Borland JBuilder, and export it as a stand-alone from there. I don't know if the free IDE Eclipse does this.
 

marius watz // amoeba
http://processing.unlekker.net/
justo


Re: creating an EXE
« Reply #2 on: May 11th, 2004, 4:44pm »

on May 11th, 2004, 3:57pm, amoeba wrote:
2. You can import your project into a full Java tool like Borland JBuilder, and export it as a stand-alone from there. I don't know if the free IDE Eclipse does this.

 
not sure if this is what you meant by #2, but you can make executable jar files if the user has java 1.2 or up installed.
 
you basically just add a a folder in your jar (you should be able to do this with any winzip/stuffit like program) META-INF and create a text file in that folder named MANIFEST.MF
 
within that you just put
Code:
Manifest-Version: 1.0
Main-Class: yourAppName

 
where yourAppName is the name of the "entry point" into your application...what should run first. make sure to return after the last line. eclipse will even generate it for you when you export as a jar...i assume this is what you were talking about, amoeba.
 
i'm pretty sure, however, that this won't open up java's appletViewer, so you'll have to make a class that makes a frame, puts the applet into it, and starts it.
 
this shouldn't be too much work for the processing team...any possiblity of adding it once you do it you realize how very convenient it is for installations and the like.
 
more info:
http://java.sun.com/docs/books/tutorial/jar/basics/index.html
 
http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html
 
amoeba

WWW
Re: creating an EXE
« Reply #3 on: May 11th, 2004, 6:25pm »

Justo, you are correct about the manifest etc. Regarding the problem of AppletViewer etc, something like the following will create a Java application which puts the BApplet in a Frame. Just replace "TheBApplet" with the name of your class.
 
Code:
import java.awt.*;
import java.awt.event.*;
 
public class TestApp extends Frame
 implements ActionListener {
  TheBApplet main; // your Processing class
 
  public TestApp() {
    super("TestApp");
 
    main=new TheBApplet();
    main.init();
    main.start();
 
    add("Center",main);
    setResizable(false);
 
    WindowAdpt WAdapter = new WindowAdpt();
    addWindowListener(WAdapter);
    setSize(800,600);
    pack();
    setTitle ("TestApp");
    show();
    this.toFront();
  }
 
  public void actionPerformed(ActionEvent newEvent) {
  }
 
  public void handleQuit() {
    System.exit(0);
  }
 
  class WindowAdpt
      extends java.awt.event.WindowAdapter {
    public void windowClosing(java.awt.event.WindowEvent event) {
      handleQuit();
    }
  }
 
  public static void main(String[] args) {
    TestApp server=new TestApp();
  }
 
}
« Last Edit: May 11th, 2004, 6:28pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
mKoser

WWW Email
Re: creating an EXE
« Reply #4 on: May 12th, 2004, 12:16am »

on May 11th, 2004, 11:09am, guybowden wrote:

The app uses the video feed from an attached webcam.

 
I might be missing something here, but none of the suggestions (both #1 and #2) seems to solve the problem... as far as I've tried it, yes you can run a .jar file as standalone (if java is installed on the machine) but you can't use the video-library since this is not supported via in browsers (and applets).
 
...am i missing something here
« Last Edit: May 12th, 2004, 12:16am by mKoser »  

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
amoeba

WWW
Re: creating an EXE
« Reply #5 on: May 14th, 2004, 11:13am »

Mikkel, you're right about Applet rights. But if you compile it into an application using the TestApp code it should work, since applications have full rights.  
 
That said, I haven't tested it with video. YMMV.
 

marius watz // amoeba
http://processing.unlekker.net/
guybowden


Re: creating an EXE
« Reply #6 on: May 14th, 2004, 6:04pm »

on May 11th, 2004, 6:25pm, amoeba wrote:
Regarding the problem of AppletViewer etc, something like the following will create a Java application which puts the BApplet in a Frame. Just replace "TheBApplet" with the name of your class.

 
Forgive me... Your code in this post - how / where would I implement this
 
I'm a Java virgin I've just downloaded Eclipse, but wouldn't have the first clue how to start..
 
Any help appreciated!
 
Cheers
Guy
 
amoeba

WWW
Re: creating an EXE
« Reply #7 on: May 16th, 2004, 10:56pm »

on May 14th, 2004, 6:04pm, guybowden wrote:
Forgive me... Your code in this post - how / where would I implement this

 
If you're a complete Java newbie you should probably try to follow some tutorials on Java itself before taking on this project. Ben has compiled some excellent references for learning Java. You should also learn to use an IDE like Eclipse, see Toxi's excellent intro for this.
 
The code I posted above should take care of most of the trouble of setting up an application. What you need to do is take your Processing code and put it inside a new class that extends BApplet.  
 
One thing to look out for when porting Processing code to "real" Java is that you need to write floating point numbers as 0.3f, 2.5f etc. Processing takes care of this for you, but in a real Java environment a decimal number without the "f" at the end is treated as a double, giving you lots of compiler errors.
« Last Edit: May 16th, 2004, 10:59pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
guybowden


Re: creating an EXE
« Reply #8 on: May 17th, 2004, 2:46pm »

Right...
 
I've got this far:
 
Worked through the Toxi tute on Eclipse - works a treat.
 
I've tested it with creating a Java Application using your TestApp class.  Again, I can get Eclipse to Run->Java Application - this works (although not full screen, I presume that eclipse doesn't allow that when testing.
 
My problem is exporting the JAR
 
I export the jar, but unfortunatly I can not run it.  Initially I got this error:
 
Code:

C:\Documents and Settings\guy\Desktop>java TestApp
Exception in thread "main" java.lang.NoClassDefFoundError: TestApp

 
I looked into the Jar file in Winzip and saw that there were only 3 class files in there - HelloP5.class, TestApp.class and TestApp$WindowAdpt.class - along with a .classpath file that looks like :
 
Code:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="C:/Program Files/processing-0068/processing-0068/lib/comm.jar"/>
    <classpathentry kind="lib" path="C:/Program Files/processing-0068/processing-0068/lib/pde.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

 
So I tried to fiddle with it a bit and add in the P5 class files that are in the export directory of P5 - the same ones that are included in the jar files that P5 creates.  I got a little further this time with the following result:
 
Code:

C:\Documents and Settings\guy\Desktop>java -cp TestApp.jar TestApp
Exception in thread "main" java.lang.NoSuchMethodError: BApplet.beginVideo(III)V
 
   at HelloP5.setup(HelloP5.java:26)
   at BApplet.init(BApplet.java:185)
   at TestApp.<init>(TestApp.java:25)
   at TestApp.main(TestApp.java:55)
 
C:\Documents and Settings\guy\Desktop>

 
And my last attempt:
 
Code:

C:\Documents and Settings\guy\Desktop>java -cp TestApp.jar;"C:/Program Files/pro
cessing-0068/processing-0068/lib/comm.jar";"C:/Program Files/processing-0068/pro
cessing-0068/lib/pde.jar" TestApp
AWTPATH C:\Program Files\Java\j2re1.4.1_05\bin\jawt.dll
 
C:\Documents and Settings\guy\Desktop>

 
This time it works - although only in a window the same size as my test P5 sketch. No full screen etc.
 
So... what I'd like to know is a: why do i need to add the path in the command line? and b: why is it not appearing full screen?
 
I'm using the Java plugin 1.4.1_05
 
Cheers
Guy
 
amoeba

WWW
Re: creating an EXE
« Reply #9 on: May 17th, 2004, 3:42pm »

Guy, congratulations on getting the application to run. The answers to your remaining questions are simple enough:
 
a: Because Java has no way of automatically knowing where your files are if you don't tell it what classpath to use. Eclipse should ideally include the classes you need in your JAR file, so that you would only need one file. I'm sure this is possible, but Toxi would be the man to ask...
 
b: Because applications don't go full-screen by default. Look at this thread for ways to make your application do this.
« Last Edit: May 17th, 2004, 3:45pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
guybowden


Re: creating an EXE
« Reply #10 on: May 17th, 2004, 4:01pm »

I'll speak to toxi about the class path stuff - that .classpath xml file doesn't do a lot then?
 
And I'm on the way to full screen now - getting the hang of this Java stuff now..  
 
Not as simple as a ctrl+enter in Flash, but i guess once its set up properly its a lot more powerful for certain applications.
 
toxi

WWW
Re: creating an EXE
« Reply #11 on: May 19th, 2004, 4:53pm »

Here's a mini launcher app i've been hacking on recently to run applets built with Processing in standalone/fullscreen mode (no dual monitor support so far though). Credit where credit is due: it's partly based on the PDE's presentation mode code and micheal's BAppletFS. although it ended up a bit more userfriendly/flexible, i hope!
 
still, consider it more or less as a starting point only...
 
downloads: jar file | source code
 
As noted elsewhere, fullscreen support requires Java 1.4 or later so make sure you've got a recent JRE installed.
 
example usages: (best put in a shell script or batch file)
Code:
java -cp applaunch.jar;myDemoApplet.jar BAppLauncher -applet myDemoApplet -f

Display "myDemoApplet" fullscreen. The app will automatically try to identify the most suitable screen resolution, based on the applet's dimensions and available display modes. Any outside area will be filled black by default.
 
Code:
java -cp applaunch.jar;myDemoApplet.jar BAppLauncher -applet myDemoApplet -sw 800 -sh 600 -bg ffff00

Display "myDemoApplet" fullscreen @ 800x600 pixels. If the applet's dimension is smaller than the screen size
the applet will be centered and the area around it filled in yellow (ffff00 in hex).
 
Code:
java -cp applaunch.jar;myDemoApplet.jar BAppLauncher -applet myDemoApplet -title hello world

Diplay "myDemoApplet" in a standard window, centered on screen (no res. switching). The window title will be set to "hello world"</p>
 
If in future the Bagel stuff will be in its own package definition this all can be even more simplified, at the moment the classpath param of the statement needs to include a .jar with a BApplet or else you'll get that error: "Exception in thread "main" java.lang.NoClassDefFoundError: BApplet"
 
Code:
usage: java -cp applaunch.jar;<user.jar> BAppLauncher [options] -applet <UserClassName>
    -h     show this help message
    -title set window title (omitted in fullscreen mode)
    -f     fullscreen mode
 
the following options are only valid if fullscreen mode is active:
    -sw    set desired screen width in pixels for fullscreen
      (automatically sets -f option)
    -sh    desired screen height in pixels...
      *if fullscreen mode is enabled, but no screen size is set explicitly,
      the app will attempt a best match
    -bg 123456  background/border colour in 6-digit hex format (eg. ff0000 for bright red)
 
press ESC or ALT+F4 (win) or COMMAND+Q (OSX) to quit application.
 

http://toxi.co.uk/
amoeba

WWW
Re: creating an EXE
« Reply #12 on: May 19th, 2004, 5:19pm »

Good job, toxi, you're a user-friendly god as ever. That looks like a useful tool for future use. I will point students who need presentation mode in the direction of this hack.
 

marius watz // amoeba
http://processing.unlekker.net/
_scloopy
Guest
Email
what about OS X?
« Reply #13 on: May 19th, 2004, 7:40pm »

Thanks Toxi! I've been trying to get it to work on OS X using the first example in the terminal, but it keeps saying "tcsh: SandBox_Futura_2.jar: Command not found." and sandbox futura is my applet from P5. Any Ideas?
 
ryan
 
_scloopy
Guest
Email
Re: creating an EXE
« Reply #14 on: May 19th, 2004, 7:42pm »

oops the command I used was
 
Code:
java -cp applauncher.jar ; SandBox_Futura_2.jar BAppLauncher -applet SandBox_Futura_2 -f
 
Pages: 1 2 

« Previous topic | Next topic »