< prev index next >

src/jdk.jpackage/share/native/libapplauncher/main.cpp

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "Platform.h"
  27 #include "PlatformString.h"
  28 #include "FilePath.h"
  29 #include "PropertyFile.h"
  30 #include "JavaVirtualMachine.h"
  31 #include "Package.h"
  32 #include "PlatformThread.h"
  33 #include "Macros.h"
  34 #include "Messages.h"
  35 
  36 
  37 #ifdef WINDOWS
  38 #include <Shellapi.h>
  39 #endif
  40 
  41 
  42 #include <stdio.h>
  43 #include <signal.h>
  44 #include <stdlib.h>
  45 
  46 /*
  47 This is the app launcher program for application packaging on Windows, Mac,
  48     and Linux.
  49 
  50 Basic approach:
  51   - Launcher (jpackageapplauncher) is executable that loads
  52     applauncher.dll/libapplauncher.dylib/libapplauncher.so
  53     and calls start_launcher below.
  54   - Reads app/package.cfg or Info.plist or app/<appname>.cfg for application
  55     launch configuration (package.cfg is property file).
  56   - Load JVM with requested JVM settings (bundled client JVM if availble,
  57     server or installed JVM otherwise).
  58   - Wait for JVM to exit and then exit from Main
  59   - To debug application by passing command line argument.
  60   - Application folder is added to the library path (so LoadLibrary()) works.
  61 
  62 Limitations and future work:
  63   - Running Java code in primordial thread may cause problems
  64     (example: can not use custom stack size).
  65     Solution used by java launcher is to create a new thread to invoke JVM.
  66     See CR 6316197 for more information.
  67 */
  68 
  69 extern "C" {
  70 
  71 #ifdef WINDOWS
  72     BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
  73             LPVOID lpvReserved) {
  74         return true;
  75     }
  76 #endif //WINDOWS
  77 
  78     JNIEXPORT bool start_launcher(int argc, TCHAR* argv[]) {
  79         bool result = false;
  80         bool parentProcess = true;
  81 
  82         // Platform must be initialize first.
  83         Platform& platform = Platform::GetInstance();
  84 
  85         try {
  86             for (int index = 0; index < argc; index++) {
  87                 TString argument = argv[index];
  88 
  89                 if (argument == _T("-Xappcds:generatecache")) {
  90                     platform.SetAppCDSState(cdsGenCache);
  91                 }
  92                 else if (argument == _T("-Xappcds:off")) {
  93                     platform.SetAppCDSState(cdsDisabled);
  94                 }
  95                 else if (argument == _T("-Xapp:child")) {
  96                     parentProcess = false;
  97                 }


 166 
 167             // Validation
 168             switch (platform.GetAppCDSState()) {
 169                 case cdsDisabled:
 170                 case cdsGenCache: {
 171                     // Do nothing.
 172                     break;
 173                 }
 174 
 175                 case cdsEnabled:
 176                 case cdsAuto: {
 177                     TString cacheFileName =
 178                             package.GetAppCDSCacheFileName();
 179 
 180                     if (FilePath::FileExists(cacheFileName) == false) {
 181                         Messages& messages = Messages::GetInstance();
 182                         TString message = PlatformString::Format(
 183                                 messages.GetMessage(
 184                                 APPCDS_CACHE_FILE_NOT_FOUND),
 185                                 cacheFileName.data());
 186                         throw FileNotFoundException(message);
 187                     }
 188                     break;
 189                 }
 190 
 191                 case cdsUninitialized: {
 192                     platform.ShowMessage(_T("Internal Error"));
 193                     break;
 194                 }
 195             }
 196 
 197             // Run App
 198             result = RunVM();
 199         } catch (FileNotFoundException &e) {
 200             platform.ShowMessage(e.GetMessage());
 201         }
 202 
 203         return result;
 204     }
 205 
 206     JNIEXPORT void stop_launcher() {
 207     }
 208 }


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "Platform.h"
  27 #include "PlatformString.h"
  28 #include "FilePath.h"
  29 #include "PropertyFile.h"
  30 #include "JavaVirtualMachine.h"
  31 #include "Package.h"

  32 #include "Macros.h"
  33 #include "Messages.h"
  34 






  35 #include <stdio.h>
  36 #include <signal.h>
  37 #include <stdlib.h>
  38 
  39 /*
  40 This is the app launcher program for application packaging on Windows, Mac,
  41     and Linux.
  42 
  43 Basic approach:
  44   - Launcher (jpackageapplauncher) is executable that loads
  45     applauncher.dll/libapplauncher.dylib/libapplauncher.so
  46     and calls start_launcher below.
  47   - Reads app/package.cfg or Info.plist or app/<appname>.cfg for application
  48     launch configuration (package.cfg is property file).
  49   - Load JVM with requested JVM settings (bundled client JVM if availble,
  50     server or installed JVM otherwise).
  51   - Wait for JVM to exit and then exit from Main
  52   - To debug application by passing command line argument.
  53   - Application folder is added to the library path (so LoadLibrary()) works.
  54 
  55 Limitations and future work:
  56   - Running Java code in primordial thread may cause problems
  57     (example: can not use custom stack size).
  58     Solution used by java launcher is to create a new thread to invoke JVM.
  59     See CR 6316197 for more information.
  60 */
  61 
  62 extern "C" {
  63 







  64     JNIEXPORT bool start_launcher(int argc, TCHAR* argv[]) {
  65         bool result = false;
  66         bool parentProcess = true;
  67 
  68         // Platform must be initialize first.
  69         Platform& platform = Platform::GetInstance();
  70 
  71         try {
  72             for (int index = 0; index < argc; index++) {
  73                 TString argument = argv[index];
  74 
  75                 if (argument == _T("-Xappcds:generatecache")) {
  76                     platform.SetAppCDSState(cdsGenCache);
  77                 }
  78                 else if (argument == _T("-Xappcds:off")) {
  79                     platform.SetAppCDSState(cdsDisabled);
  80                 }
  81                 else if (argument == _T("-Xapp:child")) {
  82                     parentProcess = false;
  83                 }


 152 
 153             // Validation
 154             switch (platform.GetAppCDSState()) {
 155                 case cdsDisabled:
 156                 case cdsGenCache: {
 157                     // Do nothing.
 158                     break;
 159                 }
 160 
 161                 case cdsEnabled:
 162                 case cdsAuto: {
 163                     TString cacheFileName =
 164                             package.GetAppCDSCacheFileName();
 165 
 166                     if (FilePath::FileExists(cacheFileName) == false) {
 167                         Messages& messages = Messages::GetInstance();
 168                         TString message = PlatformString::Format(
 169                                 messages.GetMessage(
 170                                 APPCDS_CACHE_FILE_NOT_FOUND),
 171                                 cacheFileName.data());
 172                         throw Exception(message);
 173                     }
 174                     break;
 175                 }
 176 
 177                 case cdsUninitialized: {
 178                     platform.ShowMessage(_T("Internal Error"));
 179                     break;
 180                 }
 181             }
 182 
 183             // Run App
 184             result = RunVM();
 185         } catch (Exception &e) {
 186             platform.ShowMessage(e.GetMessage());
 187         }
 188 
 189         return result;
 190     }
 191 
 192     JNIEXPORT void stop_launcher() {
 193     }
 194 }
< prev index next >