白痴做Web应用之01:第一个坑,没有创建Artifact

一、创建一个工程


话说连Idea都没用过,只有从Google开始。幸好找到一个页面 http://wiki.jetbrains.net/intellij/Main_Page 。虽说里面列Application servers的没有Jetty,只有GlassFish、JBoss和Tomcat,但是也不能太白痴了,用Creating a simple Web application and deploying it to Tomcat参考一下还是可以的。


按照里面的步骤,创建一个新Project(from scratch)。和里面的步骤稍微不同的是,没有Project不能先添加Server。在Run/Debug Configurations窗口里的Server Tab里添加完Server之后,没有看见右下角有个小小的“Fix”按钮,这就是我的第一坑啊。


二、尝试运行


步骤里面说,“we can start the application straight away: in the Project tool window, right-click index.jsp and choose Run index.jsp on the context menu”,这个右键菜单最后我也没找到,估计是因为Idea版本不同吧。


快捷键F9运行,log输出

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -DSTOP.PORT=0 -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DOPTIONS=jmx -Didea.launcher.port=7539 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA 10.app/bin -Dfile.encoding=MacRoman -classpath start.jar:/Applications/IntelliJ IDEA 10.app/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.eclipse.jetty.start.Main etc/jetty-jmx.xml /private/var/folders/Qx/Qx89S7RcE-8i-KpNGg13PU+++TI/-Tmp-/context8484410741561993358config/contexts-config.xml
53592
STOP.KEY=1hpxj8x9fe2o0
2012-01-04 15:39:37.137:WARN:oejd.ContextDeployer:ContextDeployer is deprecated. Use ContextProvider
2012-01-04 15:39:37.140:INFO:oejs.Server:jetty-8.0.4.v20111024
2012-01-04 15:39:37.173:INFO:oejdp.ScanningAppProvider:Deployment monitor /Servers/jetty-distribution-8.0.4.v20111024/webapps at interval 1
2012-01-04 15:39:37.179:INFO:oejdp.ScanningAppProvider:Deployment monitor /Servers/jetty-distribution-8.0.4.v20111024/contexts at interval 1
2012-01-04 15:39:37.188:INFO:oejd.DeploymentManager:Deployable added: /Servers/jetty-distribution-8.0.4.v20111024/contexts/javadoc.xml
2012-01-04 15:39:37.380:INFO:oejd.DeploymentManager:Deployable added: /Servers/jetty-distribution-8.0.4.v20111024/contexts/test.xml
2012-01-04 15:39:39.001:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager
2012-01-04 15:39:39.002:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager
2012-01-04 15:39:39.691:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Servers/jetty-distribution-8.0.4.v20111024/webapps/test/},/Servers/jetty-distribution-8.0.4.v20111024/webapps/test.war
2012-01-04 15:39:39.691:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Servers/jetty-distribution-8.0.4.v20111024/webapps/test/},/Servers/jetty-distribution-8.0.4.v20111024/webapps/test.war
2012-01-04 15:39:39.691:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Servers/jetty-distribution-8.0.4.v20111024/webapps/test/},/Servers/jetty-distribution-8.0.4.v20111024/webapps/test.war
2012-01-04 15:39:39.692:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Servers/jetty-distribution-8.0.4.v20111024/webapps/test/},/Servers/jetty-distribution-8.0.4.v20111024/webapps/test.war
2012-01-04 15:39:39.692:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/Servers/jetty-distribution-8.0.4.v20111024/webapps/test/},/Servers/jetty-distribution-8.0.4.v20111024/webapps/test.war
2012-01-04 15:39:39.925:INFO:oejhs.SslContextFactory:No keystore or trust store configured.  ACCEPTING UNTRUSTED CERTIFICATES!!!!!
2012-01-04 15:39:40.332:INFO:oejs.TransparentProxy:TransparentProxy @ /javadoc-proxy to http://download.eclipse.org/jetty/stable-8/apidocs
2012-01-04 15:39:40.346:INFO:oejs.AbstractConnector:Started [email protected]:8080 STARTING
2012-01-04 15:39:40.353:INFO:oejs.Server:jetty-8.0.4.v20111024
Connected to server

没有Error!我很傻的认为这就OK啦,等待着浏览器显示 “ Place your content here ” (这是我index.jsp的默认内容)。可是,浏览器却华丽丽的打开了Jetty的Home页。我试着打开/[ServiceName],期望着“ Place your content here ” 出现,结果404。第一感觉是根本没有Deploy成功嘛,但是为啥呢?


看了一下Project路径,里面多了一个“out”目录,看来它是Make了的。但是里面out/test/[project name]的out/production/[project name]都是空的。猜想那就是哪里设置不对,导致没有把该打包的文件打包?可是哪里不对啊?


在看步骤里,有一段说“IntelliJ IDEA has produced an artifact to deploy” 这个artifact是啥东西呢,在out里并没有找到啊,没办法继续google。然后找到了这个 体验IntelliJ IDEA + jetty ,才知道我得在Run/Debug Configurations窗口里的Deployment Tab里添加Artifact才行呢。


Artifact添加完毕,再运行,log输出变成了

...
Connected to server
[2012-01-04 05:39:56,010] Artifact SRM:war exploded: Artifact is being deployed, please wait...
2012-01-04 17:39:57.858:INFO:oejd.ContextDeployer:Deploy /private/var/folders/Qx/Qx89S7RcE-8i-KpNGg13PU+++TI/-Tmp-/context2126545340871068489deploy/SRM_war_exploded.xml -> o.e.j.w.WebAppContext{/SRM,file:/Users/twer/_Project/IdeaProjects/SRM/out/artifacts/SRM_war_exploded/}
2012-01-04 17:39:57.972:WARN:oejj.ObjectMBean:No mbean getter or setters found for maxCookieAge in class org.eclipse.jetty.server.session.HashSessionManager
2012-01-04 17:39:57.995:WARN:oejj.ObjectMBean:No mbean getter or setters found for sessionPath in class org.eclipse.jetty.server.session.HashSessionManager
2012-01-04 17:39:58.038:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/SRM,file:/Users/twer/_Project/IdeaProjects/SRM/out/artifacts/SRM_war_exploded/}
2012-01-04 17:39:58.038:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/SRM,file:/Users/twer/_Project/IdeaProjects/SRM/out/artifacts/SRM_war_exploded/}
2012-01-04 17:39:58.038:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/SRM,file:/Users/twer/_Project/IdeaProjects/SRM/out/artifacts/SRM_war_exploded/}
[2012-01-04 05:39:58,233] Artifact SRM:war exploded: Artifact is deployed successfully

out里面也生成了artifacts,浏览器打开的也是 “ Place your content here” 啦。


这个Artifact的坑,坑了我一个多小时...

你可能感兴趣的:(Java,Web)