A slightly better Java Launcher: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(minor updates)
m (Reverted edits by 199.48.147.37 to last version by 130.18.208.241)
 
Line 78: Line 78:
[[Category:Code Examples]]
[[Category:Code Examples]]
[[Category:Java]]
[[Category:Java]]
== A Bicycle Nomad Prepares for Re-entry ==
In 2010, Manjula Martin and her partner set out to see the world the old-fashioned way: by bicycle. With little money, no itinerary, gadgets or training, they traversed five countries and 3,500 miles and discovered a world filled with generosity. In this article, Manjula Martin describes the transition from bike to home with four rules for re-entry that are strikingly authentic, grounded, and universal.
[[http://goodvillenews.com/A-Bicycle-Nomad-Prepares-for-Re-entry-S6sLCO.html A Bicycle Nomad Prepares for Re-entry]]
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
== The World Waits For You ==
Its so easy to give up on our dreams; its so easy to do what everybody expects us to be doing; its so easy to blend in, to be like everybody else, just another person in the crowd, having nothing interested to say, nothing interesting to show, nothing interesting to share with the world. Its so easy to stay in our comfort zone, away from our doubts, fears and worries; away from change and all that is unfamiliar; away from growth and evolution; away from all the opportunities life has to offer us; away from all that is beautiful, empowering and great away from life.
[[http://goodvillenews.com/The-World-Waits-For-You-0I7WPz.html The World Waits For You]]
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
== Why Creative Thinking is Inclusive Thinking ==
"Albert Einstein was once asked what the difference was between him and the average person. He said that if you asked the average person to find a needle in the haystack, the person would stop when he or she found a needle. He, on the other hand, would tear through the entire haystack looking for all the possible needles.
[[http://goodvillenews.com/Why-Creative-Thinking-is-Inclusive-Thinking-sNMMAZ.html Why Creative Thinking is Inclusive Thinking]]
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
== Would Gandhi Use Social Media? ==
If Gandhi were alive today, would he use social media? He was never anti-technology, or even anti-changing with the times. Quite the opposite, actually. If Internet technologies and social networks were around, he would certainly have embraced them -- but with a conscious mindfulness of their strengths and weaknesses.
[[http://goodvillenews.com/Would-Gandhi-Use-Social-Media-J39i2S.html Would Gandhi Use Social Media?]]
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
== Love Everything, Be Attached To Nothing ==
As human beings we all want to be happy and free from misery we have learned that the key to happiness is inner peace. The greatest obstacles to inner peace are disturbing emotions such as anger, attachment, fear and suspicion, while love and compassion and a sense of universal responsibility are the sources of peace and happiness. Dalai Lama
[[http://goodvillenews.com/Love-Everything-Be-Attached-To-Nothing-RSJu6i.html Love Everything, Be Attached To Nothing]]
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]

Latest revision as of 17:22, 15 August 2012

Author: Pac (talk, contrib)


Description

Testing Java Launcher example, I noticed it calls the JRE's "java.exe". The problem with "java.exe" is that it will always open a command window (which must stay open for the whole execution of the child Java process - if the user accidentally closes the command window the child process dies too). So, I thought it would be better to use "javaw.exe". It will open your java application directly as a normal Windows application.

A second modification is to use ExecWait instead of Exec to launch the java process. This avoids a Windows 2000 problem (As described by the Eclipse IDE Windows launcher author in a code comment, "This launcher process must continue to process events until the JVM exits or else Windows 2K will hang if the desktop properties (e.g., background) are changed by the user. Windows does a SendMessage() to every top level window process, which blocks the caller until the process responds."). This may or may not apply here, but the exe process is so small it won't hurt.

See also Java Launcher with automatic JRE installation.

The Modified Code

; Java Launcher
;--------------
 
;You want to change the next four lines
Name "YourProgramName"
Caption "Java Launcher"
Icon "YourProgram.ico"
OutFile "YourProgram.exe"
 
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
 
;You want to change the next two lines too
!define CLASSPATH ".;lib;lib\myJar"
!define CLASS "org.me.myProgram"
 
Section ""
  Call GetJRE
  Pop $R0
 
  ; change for your purpose (-jar etc.)
  StrCpy $0 '"$R0" -classpath "${CLASSPATH}" ${CLASS}'
 
 
  SetOutPath $EXEDIR
  ExecWait $0
SectionEnd
 
Function GetJRE
;
;  Find JRE (javaw.exe)
;  1 - in .\jre directory (JRE Installed with application)
;  2 - in JAVA_HOME environment variable
;  3 - in the registry
;  4 - assume javaw.exe in current dir or PATH
 
  Push $R0
  Push $R1
 
  ClearErrors
  StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
  IfFileExists $R0 JreFound
  StrCpy $R0 ""
 
  ClearErrors
  ReadEnvStr $R0 "JAVA_HOME"
  StrCpy $R0 "$R0\bin\javaw.exe"
  IfErrors 0 JreFound
 
  ClearErrors
  ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment"
"CurrentVersion"
  ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1"
"JavaHome"
  StrCpy $R0 "$R0\bin\javaw.exe"
 
  IfErrors 0 JreFound
  StrCpy $R0 "javaw.exe"
 
 JreFound:
  Pop $R1
  Exch $R0
FunctionEnd