Commits

Sam Adams committed 0aa1791

Added .bat launcher, and Main class

  • Participants
  • Parent commits 59ee2cf

Comments (0)

Files changed (4)

         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
-            <version>2.4</version>
-            <scope>provided</scope>
+            <version>2.5</version>
+            <!--<scope>provided</scope>-->
         </dependency>
         <dependency>
             <groupId>com.google.inject</groupId>
+mvn compile jetty:run -Dchempound.workspace=e:/quixote/workspace -Dchempound.uri=http://helios:8181/ -Djetty.port=8181

File src/main/java/uk/ac/cam/ch/wwmm/quixote/QuixoteWebappLauncher.java

+package uk.ac.cam.ch.wwmm.quixote;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.servlet.ServletModule;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import org.apache.commons.io.FileUtils;
+import org.restlet.Application;
+import org.restlet.Component;
+import org.restlet.Context;
+import org.restlet.data.Protocol;
+import uk.ac.cam.ch.wwmm.chempound.DefaultChempoundModule;
+import uk.ac.cam.ch.wwmm.chempound.compchem.CompChemModule;
+import uk.ac.cam.ch.wwmm.chempound.config.ChempoundConfiguration;
+import uk.ac.cam.ch.wwmm.chempound.config.DefaultChempoundConfiguration;
+import uk.ac.cam.ch.wwmm.chempound.crystal.CrystallographyModule;
+import uk.ac.cam.ch.wwmm.chempound.datastore.JenaTripleStore;
+import uk.ac.cam.ch.wwmm.chempound.datastore.TripleStore;
+import uk.ac.cam.ch.wwmm.chempound.plugins.jmol.JmolModule;
+import uk.ac.cam.ch.wwmm.chempound.plugins.jquery.JQueryModule;
+import uk.ac.cam.ch.wwmm.chempound.storage.FileSystemResourceStore;
+import uk.ac.cam.ch.wwmm.chempound.storage.ResourceStore;
+import uk.ac.cam.ch.wwmm.chempound.webapp.ChempoundApplication;
+import uk.ac.cam.ch.wwmm.chempound.webapp.ChempoundServletModule;
+import uk.ac.cam.ch.wwmm.chempound.webapp.DefaultFreemarkerService;
+import uk.ac.cam.ch.wwmm.chempound.webapp.FreemarkerService;
+import uk.ac.cam.ch.wwmm.chempound.webapp.search.chemistry.StructureSearchProviderModule;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * @author Sam Adams
+ */
+public class QuixoteWebappLauncher {
+
+    public static void main(String[] args) throws Exception {
+        System.setProperty("chempound.workspace", "e:/quixote/workspace");
+        System.setProperty("chempound.uri", "http://helios:8181/");
+
+        Injector injector = Guice.createInjector(
+                getConfigurationModule(),
+                getChempoundModule(),
+                getServletModule(),
+                getPluginsModule(),
+                getRestletModule()
+
+        );
+
+        Component component = injector.getInstance(Component.class);
+        component.getContext().getParameters().add("maxThreads", "64");
+        component.getServers().add(Protocol.HTTP, 8181);
+        Application application = injector.getInstance(Application.class);
+        component.getDefaultHost().attach(application);
+        component.start();
+
+    }
+
+    protected static Module getConfigurationModule() {
+        return new AbstractModule() {
+            @Override
+            protected void configure() {
+                try {
+                    ChempoundConfiguration config = getConfiguration();
+                    bind(ChempoundConfiguration.class).toInstance(config);
+
+                    TripleStore dataStore = getTripleStore(config);
+                    bind(TripleStore.class).toInstance(dataStore);
+
+                    ResourceStore resourceStore = getResourceStore(config);
+                    bind(ResourceStore.class).toInstance(resourceStore);
+                } catch (IOException e) {
+                    throw new RuntimeException("Error initialising chempound", e);
+                }
+            }
+        };
+    }
+
+    protected static JenaTripleStore getTripleStore(ChempoundConfiguration config) throws IOException {
+        File dir = new File(config.getWorkspace(), "tdb/");
+        FileUtils.forceMkdir(dir);
+        Dataset dataset = TDBFactory.createDataset(dir.getPath());
+        return new JenaTripleStore(dataset);
+    }
+
+    protected static ResourceStore getResourceStore(ChempoundConfiguration config) throws IOException {
+        File dir = new File(config.getWorkspace(), "content/");
+        FileUtils.forceMkdir(dir);
+        return new FileSystemResourceStore(dir);
+    }
+
+    private static ChempoundConfiguration getConfiguration() throws IOException {
+        String workspace = System.getProperty("chempound.workspace");
+        String baseUri = System.getProperty("chempound.uri");
+        File workspaceDir = new File(workspace);
+        URI uri = URI.create(baseUri);
+        return DefaultChempoundConfiguration.load(uri, workspaceDir);
+    }
+
+    protected static Module getChempoundModule() {
+        return new DefaultChempoundModule();
+    }
+
+    protected static ServletModule getServletModule() {
+        return new ChempoundServletModule();
+    }
+
+    protected static AbstractModule getPluginsModule() {
+        return new AbstractModule() {
+            @Override
+            protected void configure() {
+
+                install(new StructureSearchProviderModule());
+                install(new CrystallographyModule());
+                install(new CompChemModule());
+
+                install(new JQueryModule());
+                install(new JmolModule());
+
+            }
+        };
+    }
+
+
+    protected static AbstractModule getRestletModule() {
+        return new AbstractModule() {
+            @Override
+            protected void configure() {
+                Component component = new Component();
+                component.getClients().add(Protocol.CLAP);
+                component.getClients().add(Protocol.FILE);
+
+                bind(FreemarkerService.class).to(DefaultFreemarkerService.class);
+
+                bind(Component.class).toInstance(component);
+                bind(Context.class).toInstance(component.getContext().createChildContext());
+                bind(Application.class).to(ChempoundApplication.class);
+            }
+        };
+
+
+    }
+
+}

File src/main/resources/log4j.properties

 log4j.appender.A.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%n
 log4j.appender.A.target = System.err
 
-# log4j.logger.uk.ac.cam.ch.wwmm.chempound = DEBUG
+log4j.logger.uk.ac.cam.ch.wwmm.chempound = DEBUG