Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo
Commits
8ae9f7c5
Commit
8ae9f7c5
authored
Dec 05, 2015
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
独立模式参数配置
parent
c33b3a10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
34 deletions
+56
-34
src/main/java/org/b3log/solo/Starter.java
src/main/java/org/b3log/solo/Starter.java
+56
-34
No files found.
src/main/java/org/b3log/solo/Starter.java
View file @
8ae9f7c5
...
@@ -21,9 +21,12 @@ import java.net.URI;
...
@@ -21,9 +21,12 @@ import java.net.URI;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.CommandLineParser
;
import
org.apache.commons.cli.CommandLineParser
;
import
org.apache.commons.cli.DefaultParser
;
import
org.apache.commons.cli.DefaultParser
;
import
org.apache.commons.cli.HelpFormatter
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.ParseException
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.util.Strings
;
import
org.b3log.latke.util.Strings
;
import
org.eclipse.jetty.server.Server
;
import
org.eclipse.jetty.server.Server
;
...
@@ -62,45 +65,66 @@ public final class Starter {
...
@@ -62,45 +65,66 @@ public final class Starter {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
Logger
logger
=
Logger
.
getLogger
(
Starter
.
class
);
final
Logger
logger
=
Logger
.
getLogger
(
Starter
.
class
);
//args = new String[]{"-lp", "9090", "-sp", "9090", "-ssp", "9090"};
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
String
arg
=
args
[
i
];
System
.
out
.
println
(
arg
);
}
final
Options
options
=
new
Options
();
final
Options
options
=
new
Options
();
final
Option
listenPortOpt
=
Option
.
builder
(
).
longOpt
(
"listen_port
"
)
final
Option
listenPortOpt
=
Option
.
builder
(
"lp"
).
longOpt
(
"listen_port"
).
argName
(
"LISTEN_PORT
"
)
.
hasArg
().
desc
(
"listen port"
).
build
();
.
hasArg
().
desc
(
"listen port
, default is 8080
"
).
build
();
options
.
addOption
(
listenPortOpt
);
options
.
addOption
(
listenPortOpt
);
final
Option
serverSchemeOpt
=
Option
.
builder
(
).
longOpt
(
"server_scheme
"
)
final
Option
serverSchemeOpt
=
Option
.
builder
(
"ss"
).
longOpt
(
"server_scheme"
).
argName
(
"SERVER_SCHEME
"
)
.
hasArg
().
desc
(
"browser visit protocol"
).
build
();
.
hasArg
().
desc
(
"browser visit protocol
, default is http
"
).
build
();
options
.
addOption
(
serverSchemeOpt
);
options
.
addOption
(
serverSchemeOpt
);
final
Option
serverHostOpt
=
Option
.
builder
(
).
longOpt
(
"server_host
"
)
final
Option
serverHostOpt
=
Option
.
builder
(
"sh"
).
longOpt
(
"server_host"
).
argName
(
"SERVER_HOST
"
)
.
hasArg
().
desc
(
"browser visit domain name"
).
build
();
.
hasArg
().
desc
(
"browser visit domain name
, default is localhost
"
).
build
();
options
.
addOption
(
serverHostOpt
);
options
.
addOption
(
serverHostOpt
);
final
Option
serverPortOpt
=
Option
.
builder
(
).
longOpt
(
"server_port
"
)
final
Option
serverPortOpt
=
Option
.
builder
(
"sp"
).
longOpt
(
"server_port"
).
argName
(
"SERVER_PORT
"
)
.
hasArg
().
desc
(
"browser visit port"
).
build
();
.
hasArg
().
desc
(
"browser visit port
, default is 8080
"
).
build
();
options
.
addOption
(
serverPortOpt
);
options
.
addOption
(
serverPortOpt
);
final
Option
staticServerSchemeOpt
=
Option
.
builder
(
).
longOpt
(
"static_server_scheme
"
)
final
Option
staticServerSchemeOpt
=
Option
.
builder
(
"sss"
).
longOpt
(
"static_server_scheme"
).
argName
(
"STATIC_SERVER_SCHEME
"
)
.
hasArg
().
desc
(
"browser visit static resource protocol"
).
build
();
.
hasArg
().
desc
(
"browser visit static resource protocol
, default is http
"
).
build
();
options
.
addOption
(
staticServerSchemeOpt
);
options
.
addOption
(
staticServerSchemeOpt
);
final
Option
staticServerHostOpt
=
Option
.
builder
(
).
longOpt
(
"static_server_host
"
)
final
Option
staticServerHostOpt
=
Option
.
builder
(
"ssh"
).
longOpt
(
"static_server_host"
).
argName
(
"STATIC_SERVER_HOST
"
)
.
hasArg
().
desc
(
"browser visit static resource domain name"
).
build
();
.
hasArg
().
desc
(
"browser visit static resource domain name
, default is localhost
"
).
build
();
options
.
addOption
(
staticServerHostOpt
);
options
.
addOption
(
staticServerHostOpt
);
final
Option
staticServerPortOpt
=
Option
.
builder
(
).
longOpt
(
"static_server_port
"
)
final
Option
staticServerPortOpt
=
Option
.
builder
(
"ssp"
).
longOpt
(
"static_server_port"
).
argName
(
"STATIC_SERVER_PORT
"
)
.
hasArg
().
desc
(
"browser visit static resource port"
).
build
();
.
hasArg
().
desc
(
"browser visit static resource port
, default is 8080
"
).
build
();
options
.
addOption
(
staticServerPortOpt
);
options
.
addOption
(
staticServerPortOpt
);
final
Option
contextPathOpt
=
Option
.
builder
().
longOpt
(
"context_path"
)
options
.
addOption
(
"h"
,
"help"
,
false
,
"print help for the command"
);
.
hasArg
().
desc
(
"context path"
).
build
();
options
.
addOption
(
contextPathOpt
);
final
Option
staticPathOpt
=
Option
.
builder
().
longOpt
(
"static_path"
)
.
hasArg
().
desc
(
"static path"
).
build
();
options
.
addOption
(
staticPathOpt
);
final
HelpFormatter
helpFormatter
=
new
HelpFormatter
();
final
CommandLineParser
commandLineParser
=
new
DefaultParser
();
final
CommandLineParser
commandLineParser
=
new
DefaultParser
();
final
CommandLine
commandLine
=
commandLineParser
.
parse
(
options
,
args
);
CommandLine
commandLine
;
final
boolean
isWindows
=
System
.
getProperty
(
"os.name"
).
toLowerCase
().
contains
(
"windows"
);
final
String
cmdSyntax
=
isWindows
?
"java -cp WEB-INF/lib/*;WEB-INF/classes org.b3log.solo.Starter"
:
"java -cp WEB-INF/lib/*:WEB-INF/classes org.b3log.solo.Starter"
;
final
String
header
=
"\nSolo is a blogging system written by Java, feel free to create your or your team own blog. 一个用 Java 编写的博客系统,为你或你的团队创建个博客吧。\n\n"
;
final
String
footer
=
"\nReport bugs or request features please visit our project website: https://github.com/b3log/solo\n\n"
;
try
{
commandLine
=
commandLineParser
.
parse
(
options
,
args
);
}
catch
(
final
ParseException
e
)
{
helpFormatter
.
printHelp
(
cmdSyntax
,
header
,
options
,
footer
,
true
);
return
;
}
if
(
commandLine
.
hasOption
(
"h"
))
{
helpFormatter
.
printHelp
(
cmdSyntax
,
header
,
options
,
footer
,
true
);
return
;
}
String
portArg
=
commandLine
.
getOptionValue
(
"listen_port"
);
String
portArg
=
commandLine
.
getOptionValue
(
"listen_port"
);
if
(!
Strings
.
isNumeric
(
portArg
))
{
if
(!
Strings
.
isNumeric
(
portArg
))
{
...
@@ -119,10 +143,6 @@ public final class Starter {
...
@@ -119,10 +143,6 @@ public final class Starter {
Latkes
.
setStaticServerHost
(
staticServerHost
);
Latkes
.
setStaticServerHost
(
staticServerHost
);
String
staticServerPort
=
commandLine
.
getOptionValue
(
"static_server_port"
);
String
staticServerPort
=
commandLine
.
getOptionValue
(
"static_server_port"
);
Latkes
.
setStaticServerPort
(
staticServerPort
);
Latkes
.
setStaticServerPort
(
staticServerPort
);
String
contextPath
=
commandLine
.
getOptionValue
(
"context_path"
);
Latkes
.
setContextPath
(
contextPath
);
String
staticPath
=
commandLine
.
getOptionValue
(
"static_path"
);
Latkes
.
setStaticPath
(
staticPath
);
logger
.
info
(
"Standalone mode, see [https://github.com/b3log/solo/wiki/standalone_mode] for more details."
);
logger
.
info
(
"Standalone mode, see [https://github.com/b3log/solo/wiki/standalone_mode] for more details."
);
Latkes
.
initRuntimeEnv
();
Latkes
.
initRuntimeEnv
();
...
@@ -135,24 +155,26 @@ public final class Starter {
...
@@ -135,24 +155,26 @@ public final class Starter {
final
int
port
=
Integer
.
valueOf
(
portArg
);
final
int
port
=
Integer
.
valueOf
(
portArg
);
contextPath
=
Latkes
.
getContextPath
();
if
(
Strings
.
isEmptyOrNull
(
contextPath
))
{
contextPath
=
"/"
;
}
final
Server
server
=
new
Server
(
port
);
final
Server
server
=
new
Server
(
port
);
final
WebAppContext
root
=
new
WebAppContext
();
final
WebAppContext
root
=
new
WebAppContext
();
root
.
setContextPath
(
contextPath
);
root
.
setContextPath
(
"/"
);
root
.
setDescriptor
(
webappDirLocation
+
"/WEB-INF/web.xml"
);
root
.
setDescriptor
(
webappDirLocation
+
"/WEB-INF/web.xml"
);
root
.
setResourceBase
(
webappDirLocation
);
root
.
setResourceBase
(
webappDirLocation
);
server
.
setHandler
(
root
);
server
.
setHandler
(
root
);
server
.
start
();
try
{
server
.
start
();
}
catch
(
final
Exception
e
)
{
logger
.
log
(
Level
.
ERROR
,
"Server start failed"
,
e
);
System
.
exit
(-
1
);
}
serverScheme
=
Latkes
.
getServerScheme
();
serverScheme
=
Latkes
.
getServerScheme
();
serverHost
=
Latkes
.
getServerHost
();
serverHost
=
Latkes
.
getServerHost
();
serverPort
=
Latkes
.
getServerPort
();
serverPort
=
Latkes
.
getServerPort
();
contextPath
=
Latkes
.
getContextPath
();
final
String
contextPath
=
Latkes
.
getContextPath
();
try
{
try
{
Desktop
.
getDesktop
().
browse
(
new
URI
(
serverScheme
+
"://"
+
serverHost
+
":"
+
serverPort
+
contextPath
));
Desktop
.
getDesktop
().
browse
(
new
URI
(
serverScheme
+
"://"
+
serverHost
+
":"
+
serverPort
+
contextPath
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment