You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2018/11/15 15:03:46 UTC
svn commit: r1846661 - in /tomcat/trunk/java/org/apache/catalina/startup:
LocalStrings.properties Tomcat.java
Author: remm
Date: Thu Nov 15 15:03:45 2018
New Revision: 1846661
URL: http://svn.apache.org/viewvc?rev=1846661&view=rev
Log:
Add a simple main method to use from a Maven packager pom.
Add new Strings to translate ... Sorry.
Modified:
tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1846661&r1=1846660&r2=1846661&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties [UTF-8] (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties [UTF-8] Thu Nov 15 15:03:45 2018
@@ -142,9 +142,11 @@ hostConfig.undeployVersion=Undeploying o
passwdUserDatabase.readFail=Failed to obtain a complete set of users from /etc/passwd
+tomcat.invalidCommandLine=Invalid command line arguments [{0}]
tomcat.baseDirMakeFail=Unable to create the directory [{0}] to use as the base directory
tomcat.baseDirNotDir=The location [{0}] specified for the base directory is not a directory
tomcat.homeDirMakeFail=Unable to create the directory [{0}] to use as the home directory
+tomcat.noContextXml=Unable to determine web application context.xml [{0}]
userConfig.database=Exception loading user database
userConfig.deploy=Deploying web application for user [{0}]
Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1846661&r1=1846660&r2=1846661&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Thu Nov 15 15:03:45 2018
@@ -17,8 +17,11 @@
package org.apache.catalina.startup;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.security.Principal;
import java.util.ArrayList;
@@ -1307,7 +1310,7 @@ public class Tomcat {
result = webAppContextXml.toURI().toURL();
} catch (MalformedURLException e) {
Logger.getLogger(getLoggerName(getHost(), contextName)).log(Level.WARNING,
- "Unable to determine web application context.xml " + docBase, e);
+ sm.getString("tomcat.noContextXml", docBase), e);
}
}
return result;
@@ -1322,8 +1325,73 @@ public class Tomcat {
}
} catch (IOException e) {
Logger.getLogger(getLoggerName(getHost(), contextName)).log(Level.WARNING,
- "Unable to determine web application context.xml " + docBase, e);
+ sm.getString("tomcat.noContextXml", docBase), e);
}
return result;
}
+
+ /**
+ * Main executable method for use with a Maven packager.
+ * @param args the command line arguments
+ * @throws Exception if an error occurs
+ */
+ public static void main(String[] args) throws Exception {
+ org.apache.catalina.startup.Tomcat tomcat = new org.apache.catalina.startup.Tomcat();
+ // Create a Catalina instance and let it parse the configuration files
+ // It will also set a shutdown hook to stop the Server when needed
+ tomcat.init(new ConfigurationSource() {
+ protected final File userDir = new File(System.getProperty("user.dir"));
+ protected final URI userDirUri = userDir.toURI();
+ @Override
+ public Resource getResource(String name) throws IOException {
+ File f = new File(name);
+ if (!f.isAbsolute()) {
+ f = new File(userDir, name);
+ }
+ if (f.isFile()) {
+ return new Resource(new FileInputStream(f), f.toURI());
+ } else {
+ throw new FileNotFoundException(name);
+ }
+ }
+ @Override
+ public URI getURI(String name) {
+ File f = new File(name);
+ if (!f.isAbsolute()) {
+ f = new File(userDir, name);
+ }
+ if (f.isFile()) {
+ return f.toURI();
+ }
+ return userDirUri.resolve(name);
+ }
+ });
+ boolean await = false;
+ String path = "";
+ // Process command line parameters
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("--war")) {
+ if (++i >= args.length) {
+ throw new IllegalArgumentException(sm.getString("tomcat.invalidCommandLine", args[i - 1]));
+ }
+ File war = new File(args[i]);
+ tomcat.addWebapp(path, war.getAbsolutePath());
+ } else if (args[i].equals("--path")) {
+ if (++i >= args.length) {
+ throw new IllegalArgumentException(sm.getString("tomcat.invalidCommandLine", args[i - 1]));
+ }
+ path = args[i];
+ } else if (args[i].equals("--await")) {
+ await = true;
+ } else {
+ throw new IllegalArgumentException(sm.getString("tomcat.invalidCommandLine", args[i]));
+ }
+ }
+ tomcat.start();
+ // Ideally the utility threads are non daemon
+ if (await) {
+ tomcat.getServer().await();
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1846661 - in /tomcat/trunk/java/org/apache/catalina/startup:
LocalStrings.properties Tomcat.java
Posted by Rémy Maucherat <re...@apache.org>.
On Thu, Nov 15, 2018 at 4:03 PM <re...@apache.org> wrote:
> Author: remm
> Date: Thu Nov 15 15:03:45 2018
> New Revision: 1846661
>
> URL: http://svn.apache.org/viewvc?rev=1846661&view=rev
> Log:
> Add a simple main method to use from a Maven packager pom.
>
https://github.com/rmaucher/tomcat-maven
Is that useful ? [will need Tomcat 9.0.14 to build obviously]
Rémy