Rectangle 27 275

JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself.

JexePack is a command line tool (great for automated scripting) that allows you to package your Java application (class files), optionally along with its resources (like GIF/JPG/TXT/etc), into a single compressed 32-bit Windows EXE, which runs using Sun's Java Runtime Environment. Both console and windowed applications are supported.

A LAX Executable is an executable file that is used to launch a Java application on any LaunchAnywhere-compatible platform. Currently, InstallAnywhere creates LaunchAnywheres on Windows 95/98/NT/2000/Me, Solaris, Linux, and Mac OS X. LaunchAnywhere enables end-users to double-click on an icon (Windows or Mac OS X) or type a single command (UNIX) to start a Java application.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 66

package example;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.daemon.*;

class EchoTask extends TimerTask {
    @Override
    public void run() {
        System.out.println(new Date() + " running ...");
    }
}

public class Main implements Daemon {

    private static Timer timer = null;

    public static void main(String[] args) {
        timer = new Timer();
        timer.schedule(new EchoTask(), 0, 1000);
    }

    @Override
    public void init(DaemonContext dc) throws DaemonInitException, Exception {
        System.out.println("initializing ...");
    }

    @Override
    public void start() throws Exception {
        System.out.println("starting ...");
        main(null);
    }

    @Override
    public void stop() throws Exception {
        System.out.println("stopping ...");
        if (timer != null) {
            timer.cancel();
        }
    }

    @Override
    public void destroy() {
        System.out.println("done.");
    }

 }
#!/bin/sh

# Setup variables
EXEC=/usr/bin/jsvc
JAVA_HOME=/usr/lib/jvm/java-6-sun
CLASS_PATH="/usr/share/java/commons-daemon.jar":"/path/to/your.jar"
CLASS=example.Main
USER=foo
PID=/tmp/example.pid
LOG_OUT=/tmp/example.out
LOG_ERR=/tmp/example.err

do_exec()
{
    $EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS
}

case "$1" in
    start)
        do_exec
            ;;
    stop)
        do_exec "-stop"
            ;;
    restart)
        if [ -f "$PID" ]; then
            do_exec "-stop"
            do_exec
        else
            echo "service not running, will do nothing"
            exit 1
        fi
            ;;
    *)
            echo "usage: daemon {start|stop|restart}" >&2
            exit 3
            ;;
esac
$ ./service start && sleep 5 && ./service stop
$ cat /tmp/example.out
initializing ...
starting ...
Fri Oct 07 16:26:54 EEST 2011 running ...
Fri Oct 07 16:26:55 EEST 2011 running ...
Fri Oct 07 16:26:56 EEST 2011 running ...
Fri Oct 07 16:26:57 EEST 2011 running ...
Fri Oct 07 16:26:58 EEST 2011 running ...
stopping ...
done.

Nice approach, but I have a one question in mind. How do you define classpath if there are more than one dependent jar files? Do I need define one by one separately as per your script?

@MMRUser: if the dependent jars are specified in your.jar manifest, you don't.

How to convert a java program to daemon with jsvc? - Stack Overflow

java daemon jsvc
Rectangle 27 96

GCJ: The GNU Compiler for Java can compile Java source code into native machine code, including Windows executables.

Although not everything in Java is supported under GCJ, especially the GUI components (see What Java API's are supported? How complete is the support? question from the FAQ). I haven't used GCJ much, but from the limited testing I've done with console applications, it seems fine.

One downside of using GCJ to create an standalone executable is that the size of the resulting EXE can be quite large. One time I compiled a trivial console application in GCJ and the result was an executable about 1 MB. (There may be ways around this that I am not aware of. Another option would be executable compression programs.)

In terms of open-source installers, the Nullsoft Scriptable Install System is a scriptable installer. If you're curious, there are user contributed examples on how to detect the presence of a JRE and install it automatically if the required JRE is not installed. (Just to let you know, I haven't used NSIS before.)

Project is actually dead, as I can see. No news on main page

The GNU Java development has pretty much moved to OpenJDK, as the non-Oracle sources could not get access to the TCK for validation.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 3

I can be forgiven for being against converting a java program to a .exe Application and I have My reasons. the Major one being that a java program can be compiled to a jar file from A lot of IDE's. When the program is in .jar format, it can run in Multiple Platforms as opposed to .exe which would run Only in very limited Environment. I am for the Idea that Java Programs shoudl not be converted to Exe unless it is very neccesary. One can always write .bat files that runs the Java program while it is a jar file.

if it is really neccesary to convert it to exe, Jar2Exe converter silently does that and one can also attach Libraries that are compiled together with the Main Application.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 30

You can try many of the java wrappers out there like JSmooth, JWrapper, and other utilities but you can also make a .bat with the following code:start javaw -jar JarFile.jar and convert the bat to an exe using any .bat to .exe converter.

A good wrapper either brings a JRE or installs it if needed and handles error situations.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 22

The latest Java Web Start has been enhanced to allow good offline operation as well as allowing "local installation". It is worth looking into.

Apparently JWS has had security tightened so much, that it requires a lot more effort than previously to get running. It might still be useful for installers, though.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 13

It's easily customizable up to the point where you want to write scripts for special actions that cannot be done with standard dialogues. But even though we're setting up windows services with it, we're only using standard components.

  • scriptable in Java
  • lots of customizable standard panels and actions
  • optionally includes or downloads a JRE
  • can also launch windows services

I think Launch4J is from the same company (just the launcher - no installer).

PS: sadly i'm not getting paid for this endorsement. I just like that tool.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 12

If you need to convert your entire application to native code, i.e. an EXE plus DLLs, there is ExcelsiorJET. I found it works well and provided an alternative to bundling a JRE.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 7

Alternatively, you can use some java-to-c translator (e.g., JCGO) and compile the generated C files to a native binary (.exe) file for the target platform.

I'm very incredulous of this method's effeciveness. I'd have to see it to believe it (think about the fact that most Java code is API calls to the JRE, and all of that isn't present on C, nevermind the differences in how the language works).

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 1

Your root problem is obviously that the conversion from Celsius to Fahrenheit is implemented incorrectly within the loop. I would approach this problem by extracting the "beef" of your application, i.e. the temperature conversion (formula of which is in Wikipedia), into a method of its own:

/**
 * Converts the input Celsius temperature into Fahrenheit degrees, using the
 * formula:
 * 
 * <pre>
 * (degreesCelsius * 1.8) + 32 = degreesFahrenheit
 * </pre>
 * 
 * @param degreesCelsius
 *            temperature in Celsius degrees
 * @return the temperature in Fahrenheit degrees
 */
private static float celsiusToFahrenheit(float degreesCelsius) {
    return (degreesCelsius * 1.8f) + 32.0f;
}

You should separate the calculation from the rest of the code because it:

  • Improves the readability of your code

After you have done the above, the rest of the code only handles the initialization of the range and iterating over it:

// define the range
final int cMin = 30;
final int cMax = 40;

// run the conversion
for (int i = cMax; i >= cMin; i--) {
    float degreesCelsius = (float) i;
    float degreesFahrenheit = celsiusToFahrenheit(degreesCelsius);
    System.out.println(String.format("%.1f\t|\t%.1f", degreesCelsius,
            degreesFahrenheit));
}

Note that I've declared the Celsius degree range as ints because the requirement was an increment of one degree between each conversion. The values are cast into floats before the calculation.

You should avoid magic numbers in your code, which is why the range is defined as a pair of final variables (which you could also parse out from the args array, if you want to accept user input). The range could also be defined as static final fields if you don't expect it to change between runs of the program.

Finally, utility class Formatter is used for outputting the data through String.format(). This makes it easy to change the precision of the float values in the output.

Java Fahrenheit=Celsius Program Issue - Stack Overflow

java
Rectangle 27 4

Are you 100% sure you need to use jsvc? If you just want to have your application bind to a port and run at boot time, you don't need to use it. jsvc allows your application to bind to a privileged port (<1024) and then resume running as a normal user.

Actually I am sure because I am expected to do so. But I really dont know how to do that

jsvc also gives you things like startup error handling, PID tracking, and clean shutdown. It can be tricky to get a Java-based app running as a Linux service without those features.

How to convert a java program to daemon with jsvc? - Stack Overflow

java daemon jsvc
Rectangle 27 6

I would say launch4j is the best tool for converting a java source code(.java) to .exe file You can even bundle a jre with it for distribution and the exe can even be iconified. Although the size of application increases, it makes sure that the application will work perfectly even if the user does not have a jre installed. It also makes sure that you are able to provide the specific jre required for your app without the user having to install it separately. But unfortunately, java loses its importance. Its multi platform support is totally ignored and the final app is only supported for windows. But that is not a big deal, if you are catering only to windows users.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 3

Check out the Jakarta Commons Daemon documentation. There's an example of how to implement the Daemon interface on their wiki. Once you've implemented Daemon, you should be able to start the process by following the "Starting jsvc" and "Using jsvc" docs.

How to convert a java program to daemon with jsvc? - Stack Overflow

java daemon jsvc
Rectangle 27 2

There are 26 letters from A to Z. Your system is base 26, not 27.

What you'll probably want to do is:

Java uses Unicode, not ASCII. 65 is the one (for some characters, two are required) UTF-16 code unit value for 'A', a 16-bit number.

java - Program to convert numbers to letters - Stack Overflow

java base letters
Rectangle 27 2

There are 26 letters from A to Z. Your system is base 26, not 27.

What you'll probably want to do is:

Java uses Unicode, not ASCII. 65 is the one (for some characters, two are required) UTF-16 code unit value for 'A', a 16-bit number.

java - Program to convert numbers to letters - Stack Overflow

java base letters
Rectangle 27 2

Here is what might help you : leave blank the text field which you want to be populated( leave blank fahrenheit if you want to convert from celsius to fahrenheit ).

@Override
public void actionPerformed(final ActionEvent e) {
    double celsius = 0, fahrenheit = 0;
    DecimalFormat twoDigits = new DecimalFormat("0.00");
    if (Temperature_Converter.this.TFCelsius.getText() == null || "".equals(Temperature_Converter.this.TFCelsius.getText().trim())) {
        // convert from fahrenheit to celsius
        fahrenheit = Double.parseDouble(Temperature_Converter.this.TFFahrenheit.getText());
        celsius = (fahrenheit - Temperature_Converter.offset) *   Temperature_Converter.FahrenheitTOCelsius;
        Temperature_Converter.this.TFCelsius.setText(" " + twoDigits.format(celsius));
    } else if (Temperature_Converter.this.TFFahrenheit.getText() == null || "".equals(Temperature_Converter.this.TFFahrenheit.getText().trim())) {
           // convert from celsius to fahrenheit
           celsius = Double.parseDouble(Temperature_Converter.this.TFCelsius.getText());
           fahrenheit = celsius * Temperature_Converter.CelsiusTOFarenheit + Temperature_Converter.offset;
           Temperature_Converter.this.TFFahrenheit.setText(" " + twoDigits.format(fahrenheit));
    }
}

Edit : You can validate the user input text and alert the user if there are something else then numbers introduced as a temperature.

try {
    fahrenheit = Double.parseDouble(Temperature_Converter.this.TFFahrenheit.getText());
} catch (NumberFormatException e1) {
     //alert the user       
    JOptionPane.showMessageDialog(null, "You are allowed to introduce numbers only for temperature");
    return;
}

This was great. It fixed my issue completely. I knew there should have been an if statement somewhere I just didn't know how to go about it. My CS logic is still not the best. Thanks!

@Mowza2k2 you are developing your CS logic by doing this kind of problems. Keep going on and you will advance a lot. By the way , watch the edit part of the post for user friendly alert message.

thank you so much. Everything you posted made sense to me, though I didn't know how to go about it myself. It's nice to have somewhere to go where I can get some help (without bugging my professor).

@Mowza2k2 you are very welcome. I'm happy you feel welcome in the community and that you find your answers here.

user interface - Java GUI Fahrenheit/Celsius Converter with a Button -...

java user-interface temperature
Rectangle 27 3

You can convert jar to exe using jar2exe. However you need to purchase the software. If you need a open source software i would suggest JSmooth.

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 3

You can use Janel. This last works as an application launcher or service launcher (available from 4.x).

installer - How can I convert my Java program to an .exe file? - Stack...

java installer exe
Rectangle 27 4

An interpreter is a software program that converts code from high level language to machine format.

No. That's a compiler. An interpreter is a computer program that executes the instructions written in a language. See wikipedia. This is different from a compiler that converts a higher level language into a lower language. The C compiler goes from C to assembly code with the assembler (another type of compiler) translates from assembly to machine code. In Java, the java compiler does code verification and converts from source to bytecode.

now platform for a java interpreter is the JVM, in which it runs, so basically it is going to produce code which can be run by JVM.

The JVM operates on the bytecode directly. The java interpreter is integrated so closely with the JVM that they shouldn't really be thought of as separate entities. What also is happening is a crap-ton of optimization where bytecode is basically optimized (think cc -O3) and inlined on the fly. This makes calling it just an interpreter seem inadequate.

so it takes the bytecode produces intermediate code and the target machine code and gives it to JVM.

JVM in turns executes that code on the OS platform in which JVM is implemented or being run.

I'd rather say that the JVM uses the bytecode, optimized user code, the java libraries which include java and native code, in conjunction with OS calls to execute java applications.

now i am still not clear with the sub process that happens in between i.e. 1. interpreter produces intermediate code. 2. interpreted code is then optimized. 3. then target code is generated 4. and finally executed.

No. The Java compiler generates bytecode. When the JVM executes the code, steps 2-4 happen at runtime inside of the JVM. It is very different than C (for example) which has these separate steps being run by different utilities. Don't think about this as "subprocesses".

Yes although at some point the OS and the CPU come into effect.

and does executing means it gets executed in JVM or in the underlying OS ?

Uh, it gets executed by/in the JVM which is running as a process inside of an OS with the CPU and the rest of the hardware architecture responsible for executing the machine code.

thanks for such a nice explanation, still this topic is very vast and pretty confusing, i am taking my time to get it. Also in case of c its the assembly language which then translated to machine code by assembler compiler, so in case of JAVA, the bytecode can be taken as (just for example) equivalent to assembly code which then translated to machine code by java interpreter and then executed.

A C compiler is a compiler ... not an interpreter. It may compile to assembly code that this then translated to native code. Alternatively, it may compile directly to machine code.

You keep on trying to use words from the C realm to describe what's happening with Java and the JVM and they really don't apply or are vastly different so any comparison is comfusing @RajanChauhan. See my and Stephen's answer for more details.

jvm - How exactly does the Java interpreter or any interpreter work? -...

java jvm interpreter
Rectangle 27 4

An interpreter is a software program that converts code from high level language to machine format.

No. That's a compiler. An interpreter is a computer program that executes the instructions written in a language. See wikipedia. This is different from a compiler that converts a higher level language into a lower language. The C compiler goes from C to assembly code with the assembler (another type of compiler) translates from assembly to machine code. In Java, the java compiler does code verification and converts from source to bytecode.

now platform for a java interpreter is the JVM, in which it runs, so basically it is going to produce code which can be run by JVM.

The JVM operates on the bytecode directly. The java interpreter is integrated so closely with the JVM that they shouldn't really be thought of as separate entities. What also is happening is a crap-ton of optimization where bytecode is basically optimized (think cc -O3) and inlined on the fly. This makes calling it just an interpreter seem inadequate.

so it takes the bytecode produces intermediate code and the target machine code and gives it to JVM.

JVM in turns executes that code on the OS platform in which JVM is implemented or being run.

I'd rather say that the JVM uses the bytecode, optimized user code, the java libraries which include java and native code, in conjunction with OS calls to execute java applications.

now i am still not clear with the sub process that happens in between i.e. 1. interpreter produces intermediate code. 2. interpreted code is then optimized. 3. then target code is generated 4. and finally executed.

No. The Java compiler generates bytecode. When the JVM executes the code, steps 2-4 happen at runtime inside of the JVM. It is very different than C (for example) which has these separate steps being run by different utilities. Don't think about this as "subprocesses".

Yes although at some point the OS and the CPU come into effect.

and does executing means it gets executed in JVM or in the underlying OS ?

Uh, it gets executed by/in the JVM which is running as a process inside of an OS with the CPU and the rest of the hardware architecture responsible for executing the machine code.

thanks for such a nice explanation, still this topic is very vast and pretty confusing, i am taking my time to get it. Also in case of c its the assembly language which then translated to machine code by assembler compiler, so in case of JAVA, the bytecode can be taken as (just for example) equivalent to assembly code which then translated to machine code by java interpreter and then executed.

A C compiler is a compiler ... not an interpreter. It may compile to assembly code that this then translated to native code. Alternatively, it may compile directly to machine code.

You keep on trying to use words from the C realm to describe what's happening with Java and the JVM and they really don't apply or are vastly different so any comparison is comfusing @RajanChauhan. See my and Stephen's answer for more details.

jvm - How exactly does the Java interpreter or any interpreter work? -...

java jvm interpreter