Ich versuche, eine ausführbare Krieg für ein Frühjahr MVC-Projekt mit Embedded Jetty zu machen. Ich möchte den Krieg mit dem Befehl java -jar myProject.war starten und die Hauptklasse starten. Ich möchte nur die Maven-Krieg-Plugin verwenden, aber es ist nichtErstellen Sie einen ausführbaren Krieg für Spring MVC und Jetty Embedded-Projekt mit Maven
ist dies die Klasse MAin
public class Main
{
\t public static void main(String... anArgs) throws Exception
{
new Main().start();
}
\t private WebServer server;
public Main()
{
server = new WebServer(8024);
}
public void start() throws Exception
{
server.start();
server.join();
}
}
und dies ist der WebServerClass funktioniert
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
/**
* Example WebServer class which sets up an embedded Jetty
* appropriately whether running in an IDE or in "production"
* mode in a shaded jar.
*/
public class WebServer
{
\t static Logger log = Logger.getLogger(WebServer.class.getName());
// TODO: You should configure this appropriately for
// your environment
private static final String LOG_PATH =
"D:/workspace/Butuc/logs/yyyy_mm_dd.request.log";
private static final String WEB_XML =
"META-INF/webapp/WEB-INF/web.xml";
private static final String CLASS_ONLY_AVAILABLE_IN_IDE =
"com.sjl.IDE";
private static final String PROJECT_RELATIVE_PATH_TO_WEBAPP =
"src/main/java/META-INF/butuc";
public static interface WebContext
{
public File getWarPath();
public String getContextPath();
}
private Server server;
private int port;
private String bindInterface;
public WebServer(int aPort)
{
this(aPort, null);
}
public WebServer(int aPort, String aBindInterface)
{
port = aPort;
bindInterface = aBindInterface;
}
public void start() throws Exception
{
server = new Server(createThreadPool());
server.addConnector(createConnector());
server.setHandler(createHandlers());
server.setStopAtShutdown(true);
server.start();
}
public void join() throws InterruptedException
{
server.join();
}
public void stop() throws Exception
{
server.stop();
}
private ThreadPool createThreadPool()
{
// TODO: You should configure these appropriately
// for your environment - this is an example only
QueuedThreadPool _threadPool = new QueuedThreadPool();
_threadPool.setMinThreads(10);
_threadPool.setMaxThreads(100);
return _threadPool;
}
private ServerConnector createConnector()
{
\t HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
\t ServerConnector _connector = new ServerConnector(server, httpConnectionFactory);
_connector.setPort(port);
_connector.setHost(bindInterface);
return _connector;
}
private HandlerCollection createHandlers()
{
WebAppContext _ctx = new WebAppContext();
_ctx.setContextPath("/");
if(isRunningInShadedJar())
{
_ctx.setWar(getShadedWarUrl());
}
else
{
_ctx.setWar(PROJECT_RELATIVE_PATH_TO_WEBAPP);
}
List<Handler> _handlers = new ArrayList<Handler>();
_handlers.add(_ctx);
HandlerList _contexts = new HandlerList();
_contexts.setHandlers(_handlers.toArray(new Handler[0]));
RequestLogHandler _log = new RequestLogHandler();
_log.setRequestLog(createRequestLog());
HandlerCollection _result = new HandlerCollection();
_result.setHandlers(new Handler[] {_contexts, _log});
return _result;
}
private RequestLog createRequestLog()
{
NCSARequestLog _log = new NCSARequestLog();
File _logPath = new File(LOG_PATH);
_logPath.getParentFile().mkdirs();
_log.setFilename(_logPath.getPath());
_log.setRetainDays(90);
_log.setExtended(false);
_log.setAppend(true);
_log.setLogTimeZone("GMT");
_log.setLogLatency(true);
return _log;
}
private boolean isRunningInShadedJar()
{
try
{
Class.forName(CLASS_ONLY_AVAILABLE_IN_IDE);
return false;
}
catch(ClassNotFoundException anExc)
{
return true;
}
}
private URL getResource(String aResource)
{
return Thread.currentThread().
getContextClassLoader().getResource(aResource);
}
private String getShadedWarUrl()
{
\t String _urlStr = getResource(WEB_XML).toString();
// Strip off "WEB-INF/web.xml"
return _urlStr.substring(0, _urlStr.length() - 15);
}
}
und dies ist die Ausnahme
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri Apr 29 10:02:30 CET 2016]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/persistence-config.xml]
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/persistence-config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:318)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:781)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:425)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:773)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:275)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1321)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:725)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:490)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.Server.start(Server.java:348)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:296)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at com.binov.web.WebServer.start(WebServer.java:71)
at com.binov.web.Main.start(Main.java:19)
at com.binov.web.Main.main(Main.java:7)
WARN : org.eclipse.jetty.webapp.WebAppContext - Failed startup of context [email protected]{/,file:/tmp/jetty-0.0.0.0-8024-webapp-_-any-/webapp/,STARTING}{jar:file:/home/binov4/workspaceJEE/ProjectFranchiseJetty/target/franchise-jar-with-dependencies.jar!/META-INF/webapp/}
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/persistence-config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:318)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:781)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:425)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:773)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:275)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1321)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:725)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:490)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.Server.start(Server.java:348)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:296)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at com.binov.web.WebServer.start(WebServer.java:71)
at com.binov.web.Main.start(Main.java:19)
at com.binov.web.Main.main(Main.java:7)
Ihre Antwort ist gut ausführen und eine ausführbare jar machen, aber wenn ich es zeigt eine Ausnahme laufen. Ich werde die WebServer-Klasse –
hinzufügen Bitte überprüfen Sie meine Frage erneut. –
Was ist die Ausnahme? – ares