Maven Jetty 插件及数据源配置
2010-09-06 15:57
423 查看
一直以来做JSP开发使用的都是Eclipse+Tomcat,虽然IDE工具带来了巨大的便利性,但是基于JAVA的IDE最大的一个特点就是占用资源。
maven 是优秀的项目管理工具,最近的项目逐渐转向了使用maven管理,命令行式的操作,让我怀念起了linux的那些岁月。
大凡web项目都会用到数据库,本文就maven下,jetty服务器中配置数据源简单说明,希望对大家有帮助:)
1)使用maven创建项目web项目
2)JNDI配置: 在项目的src/main/resources/目录下创建jetty-env.xml
3) 在web.xml中加入对
3) jetty-maven-plugin:
在项目的pom.xml中加入jetty-maven-plugin
4)访问数据源示例:
maven 是优秀的项目管理工具,最近的项目逐渐转向了使用maven管理,命令行式的操作,让我怀念起了linux的那些岁月。
大凡web项目都会用到数据库,本文就maven下,jetty服务器中配置数据源简单说明,希望对大家有帮助:)
1)使用maven创建项目web项目
mvn archetype:create -DgroupId=sample -DartifactId=sample -DarchetypeArtifactId=maven-archetype-webapp
2)JNDI配置: 在项目的src/main/resources/目录下创建jetty-env.xml
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.webapp.WebAppContext"> <!-- MsSqlServer DataSource --> <New id="sample" class="org.mortbay.jetty.plus.naming.Resource"> <Arg>jdbc/sample</Arg> <Arg> <New class="org.apache.commons.dbcp.BasicDataSource"> <Set name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</Set> <Set name="url">jdbc:sqlserver://127.0.0.1:1433;databaseName=sample;</Set> <Set name="username">sa</Set> <Set name="password">sa</Set> </New> </Arg> </New> </Configure>
3) 在web.xml中加入对
<resource-ref> <description>Microsoft SQL Server 2000 Datasource</description> <res-ref-name>jdbc/sample</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
3) jetty-maven-plugin:
在项目的pom.xml中加入jetty-maven-plugin
<build> … <plugins> … <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.25</version> <configuration> <jettyEnvXml>src/main/resources/jetty-env.xml</jettyEnvXml> <scanIntervalSeconds>10</scanIntervalSeconds> </configuration> <dependencies> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> <type>jar</type> </dependency> <dependency> <groupId>microsoft</groupId> <artifactId>sqljdbc</artifactId> <version>2.0.1803</version> <type>jar</type> </dependency> </dependencies> </plugin> </plugins> </build>
4)访问数据源示例:
Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(“java:comp/env”); DataSource ds = (DataSource) envCtx.lookup(“jdbc/sample”);
相关文章推荐
- jetty,tomcat maven插件配置数据源
- Eclipse下通过Maven的Jetty插件运行Web工程的配置,包括启动https
- Maven配置Jetty中的JNDI数据源
- Eclipse下通过Maven的Jetty插件运行Web工程的配置,包括启动https
- maven中jetty插件配置
- Java学习之Idea使用Maven配置Jetty插件
- Eclipse下通过Maven的Jetty插件运行Web工程的配置,包括启动https
- Jetty在win10上的配置,IDEA中配置Jetty,Maven中配置Jetty插件,Eclipse中配置Jetty插件及其使用,通过java代码内嵌Jetty Server
- maven项目配置jetty9插件
- Maven Jetty插件配置
- Eclipse maven jetty插件配置虚拟目录
- maven-jetty-plugin插件的配置
- maven eclipse tomcat jetty 插件配置与启动
- Eclipse下通过Maven的Jetty插件运行Web工程的配置,包括启动https
- maven jetty插件配置启动restful-web
- eclipse maven 使用 jetty 插件配置
- Maven配置tomcat和jetty插件来运行项目
- Eclipse下通过Maven的Jetty插件运行Web工程的配置
- Eclipse下通过Maven的Jetty插件运行Web工程的配置
- Maven Jetty插件配置