Project

General

Profile

« Previous | Next » 

Revision 9abea1c6

Added by Andreas Kohlbecker almost 11 years ago

fixing cdm-server development run mode: server can now run from cdmlib-webapp-source folder and has classpath to all other cdmlib sources set up correctly

View differences:

ide/eclipse/cdm-server - start.launch
13 13
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
14 14
</listAttribute>
15 15
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="eu.etaxonomy.cdm.server.Bootloader"/>
16
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-webapp=${workspace_loc:cdmlib-remote-webapp/target/cdmserver/}&#13;&#10;-jmx"/>
16
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-webapp=${workspace_loc:cdmlib-remote-webapp/src/main/webapp/}&#10;-webappClasspath=${project_classpath:cdmlib-remote-webapp}&#13;&#10;-jmx"/>
17 17
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="cdm-server"/>
18 18
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx1200M&#13;&#10;&#13;&#10;-XX:PermSize=128m &#13;&#10;-XX:MaxPermSize=390m&#13;&#10;&#13;&#10;-XX:+UseConcMarkSweepGC &#13;&#10;-XX:+CMSClassUnloadingEnabled &#13;&#10;-XX:+CMSPermGenSweepingEnabled&#13;&#10;&#13;&#10;-Dorg.eclipse.jetty.util.log.DEBUG=false&#13;&#10;&#13;&#10;-Dcom.sun.management.jmxremote.ssl=false&#13;&#10;-Dcom.sun.management.jmxremote.authenticate=false&#13;&#10;-Dcom.sun.management.jmxremote.port=9999"/>
19 19
</launchConfiguration>
src/main/java/eu/etaxonomy/cdm/server/Bootloader.java
17 17
import static eu.etaxonomy.cdm.server.CommandOptions.JMX;
18 18
import static eu.etaxonomy.cdm.server.CommandOptions.LOG_DIR;
19 19
import static eu.etaxonomy.cdm.server.CommandOptions.WEBAPP;
20
import static eu.etaxonomy.cdm.server.CommandOptions.WEBAPP_CLASSPATH;
20 21
import static eu.etaxonomy.cdm.server.CommandOptions.WIN32SERVICE;
21 22

  
22 23
import java.io.BufferedReader;
......
120 121

  
121 122
    private String logPath = null;
122 123

  
124
    private String webAppClassPath = null;
125

  
123 126
    private Server server = null;
124 127
    private final ContextHandlerCollection contexts = new ContextHandlerCollection();
125 128

  
......
262 265
        tempDir = null;
263 266

  
264 267

  
265
         // WARFILE
266
         if(cmdLine.hasOption(WEBAPP.getOpt())){
267
             cdmRemoteWebAppFile = new File(cmdLine.getOptionValue(WEBAPP.getOpt()));
268
             if(cdmRemoteWebAppFile.isDirectory()){
269
                 logger.info("using user defined web application folder: " + cdmRemoteWebAppFile.getAbsolutePath());
270
             } else {
271
                 logger.info("using user defined warfile: " + cdmRemoteWebAppFile.getAbsolutePath());
272
             }
273
             if(isRunningFromCdmRemoteWebAppSource()){
274
                 //TODO check if all local paths are valid !!!!
275
                defaultWebAppFile = new File("./src/main/webapp");
276

  
277
             } else {
278
                defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
279
             }
280
         } else {
281
             // read version number
282
             String version = readCdmRemoteVersion();
283

  
284
             cdmRemoteWebAppFile = extractWar(CDMLIB_REMOTE_WEBAPP + "-" + version);
285
             defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
286
         }
268
        // WEBAPP options
269
        //   prepare web application files to run either from war files (production mode)
270
        //   or from source (development mode)
271
        if(cmdLine.hasOption(WEBAPP.getOpt())){
287 272

  
288
         // HTTP Port
289
         int httpPort = 8080;
290
         if(cmdLine.hasOption(HTTP_PORT.getOpt())){
291
             try {
292
                httpPort = Integer.parseInt(cmdLine.getOptionValue(HTTP_PORT.getOpt()));
293
                logger.info(HTTP_PORT.getOpt()+" set to "+cmdLine.getOptionValue(HTTP_PORT.getOpt()));
294
            } catch (NumberFormatException e) {
295
                logger.error("Supplied portnumber is not an integer");
296
                System.exit(-1);
273
            cdmRemoteWebAppFile = new File(cmdLine.getOptionValue(WEBAPP.getOpt()));
274
            if(cdmRemoteWebAppFile.isDirectory()){
275
                logger.info("using user defined web application folder: " + cdmRemoteWebAppFile.getAbsolutePath());
276
            } else {
277
                logger.info("using user defined warfile: " + cdmRemoteWebAppFile.getAbsolutePath());
297 278
            }
298
         }
279

  
280
            // load the default-web-application from source if running in development mode mode
281
            if(isRunningFromCdmRemoteWebAppSource()){
282
                //TODO check if all local paths are valid !!!!
283
               defaultWebAppFile = new File("./src/main/webapp");
284
            } else {
285
               defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
286
            }
287

  
288
            if(isRunningFromCdmRemoteWebAppSource()){
289
                if(cmdLine.hasOption(WEBAPP_CLASSPATH.getOpt())){
290
                    String classPathOption = cmdLine.getOptionValue(WEBAPP_CLASSPATH.getOpt());
291
                    normalizeClasspath(classPathOption);
292
//                    webAppClassPath = classPathOption;
293
                }
294
            }
295
        } else {
296
            // read version number
297
            String version = readCdmRemoteVersion();
298
            cdmRemoteWebAppFile = extractWar(CDMLIB_REMOTE_WEBAPP + "-" + version);
299
            defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
300
        }
301

  
302

  
303
        // HTTP Port
304
        int httpPort = 8080;
305
        if(cmdLine.hasOption(HTTP_PORT.getOpt())){
306
            try {
307
               httpPort = Integer.parseInt(cmdLine.getOptionValue(HTTP_PORT.getOpt()));
308
               logger.info(HTTP_PORT.getOpt()+" set to "+cmdLine.getOptionValue(HTTP_PORT.getOpt()));
309
           } catch (NumberFormatException e) {
310
               logger.error("Supplied portnumber is not an integer");
311
               System.exit(-1);
312
           }
313
        }
299 314

  
300 315
         if(cmdLine.hasOption(DATASOURCES_FILE.getOpt())){
301 316
             logger.error(DATASOURCES_FILE.getOpt() + " NOT JET IMPLEMENTED!!!");
......
376 391
        }
377 392
    }
378 393

  
394
    /**
395
     * @param classpath
396
     */
397
    private void normalizeClasspath(String classpath) {
398
        StringBuilder classPathBuilder = new StringBuilder((int) (classpath.length() * 1.2));
399
        String[] cpEntries = classpath.split("[\\:]");
400
        for(String cpEntry : cpEntries){
401
            classPathBuilder.append(',');
402
//            if(cpEntry.endsWith(".jar")){
403
//                classPathBuilder.append("jar:");
404
//            }
405
            classPathBuilder.append(cpEntry);
406
        }
407
        webAppClassPath = classPathBuilder.toString();
408
    }
409

  
379 410
    public String readCdmRemoteVersion() throws IOException {
380 411
        String version = "cdmlib version unreadable";
381 412
        InputStream versionInStream = Bootloader.class.getClassLoader().getResourceAsStream(VERSION_PROPERTIES_FILE);
......
499 530
             * dependencies of the webapplication can be found. Otherwise
500 531
             * the system classloader would load these resources.
501 532
             */
502
            String classPath = System.getProperty("java.class.path");
503
            logger.info("Running webapp from source folder, thus adding system property 'java.class.path=" + classPath +"'  to WebAppClassLoader");
504 533
            WebAppClassLoader classLoader = new WebAppClassLoader(cdmWebappContext);
505
            classLoader.addClassPath(classPath);
534
//            String classPath = System.getProperty("java.class.path");
535
//            logger.info("Running cdmlib-remote-webapp from source folder:, thus adding system property 'java.class.path=" + classPath +"'  to WebAppClassLoader");
536
//            classLoader.addClassPath(classPath);
537
            if(webAppClassPath != null){
538
                logger.info("Running cdmlib-remote-webapp from source folder: Adding class path supplied by option '-" +  WEBAPP_CLASSPATH.getOpt() +" =" + webAppClassPath +"'  to WebAppClassLoader");
539
                classLoader.addClassPath(webAppClassPath);
540
            } else {
541
                throw new RuntimeException("Classpath cdmlib-remote-webapp for missing while running cdmlib-remote-webapp from source folder. Please supplied cdm-server option '-" +  WEBAPP_CLASSPATH.getOpt() +"");
542
            }
506 543
            cdmWebappContext.setClassLoader(classLoader);
507 544
        }
508 545

  
src/main/java/eu/etaxonomy/cdm/server/CommandOptions.java
32 32
            .hasArg()
33 33
            .withDescription( "Defines the webapplication to run from, this either can be a compressed war or extracted file.\n" +
34 34
                    "Defaults to the cdm-remote-webapp.war which is found in cdm-server/traget\n" +
35
                    "If this option is used extraction of the war from the cdmserver jar file is omitted.\n \n" +
36
                    "Using the following paths developers can run the cdmlib-remote-webapp instaces completely from the target folder or from source:\n" +
37
                    " - '{cdmlib-project-root}/cdmlib-remote-webapp/target/cdmserver'\n " +
38
                    " - '{cdmlib-project-root}/cdmlib-remote-webapp/src/main/webapp'\n" +
39
                    "This will also affect the cdm-server project, if any of both paths is set cdm-server will be run using the cdm-server/src/main/webapp folder!" )
35
                    "If this option is used extracting the war from the cdmserver jar file is omitted.\n \n" +
36
                    "DEVELOPMENT MODE:\n" +
37
                    "  If the specified path points to a directory the cdm-server will run in development mode.\n" +
38
                    "  In development mode the default webapplication containing the cdm-server management web \n" +
39
                    "  interface will be loaded from the source folder cdm-server/src/main/webapp. In normal \n" +
40
                    "  mode the default-webapp.war file will be used insead.\n" +
41
                    "  Using the following paths developers can run the cdmlib-remote-webapp instaces completely\n" +
42
                    "  from the target folder or from source (examples are for the eclipse ide):\n" +
43
                    "   - run from maven target: '{cdmlib-project-root}/cdmlib-remote-webapp/target/cdmserver'\n " +
44
                    "   - run from source: '{cdmlib-project-root}/cdmlib-remote-webapp/src/main/webapp'\n" +
45
                    "     When running from source you must also set the webapp-classpath option: \n" +
46
                    "     -webappClasspath=${project_classpath} " )
40 47
            .create("webapp");
41 48

  
49
  @SuppressWarnings("static-access")
50
    public static final Option WEBAPP_CLASSPATH = OptionBuilder
51
            .withArgName("classpath")
52
            .hasArg()
53
            .withDescription("Sets the classpath for the cdmlib-remote-webapp instance when running from source code." +
54
                    " See option -webapp")
55
            .create("webappClasspath");
56

  
42 57
    @SuppressWarnings("static-access")
43 58
    public static final Option HTTP_PORT = OptionBuilder
44 59
            .withArgName("httpPortNumber")
......
56 71

  
57 72
    @SuppressWarnings("static-access")
58 73
    public static final Option DATASOURCES_FILE = OptionBuilder
59
    .withArgName("datasourcesfile")
60
    .hasArg()
61
    .withDescription( "use the specified datasources file. Default is {user.home}/.cdmLibrary/datasources.xml")
62
    .create("datasources");
74
        .withArgName("datasourcesfile")
75
        .hasArg()
76
        .withDescription( "use the specified datasources file. Default is {user.home}/.cdmLibrary/datasources.xml")
77
        .create("datasources");
63 78

  
64 79

  
65 80

  
......
69 84
            options = new Options();
70 85
            options.addOption(HELP);
71 86
            options.addOption(WEBAPP);
87
            options.addOption(WEBAPP_CLASSPATH);
72 88
            options.addOption(HTTP_PORT);
73 89
            options.addOption(LOG_DIR);
74 90
            options.addOption(DATASOURCES_FILE);

Also available in: Unified diff