您的位置:首页 > 编程语言 > Java开发

关于eclipse中工程project的实质区别研究与猜测

2016-01-20 10:29 585 查看


关于eclipse中工程project的实质区别研究与猜测

标签: eclipsedocumentationfacettomcatservermyeclipse
2012-04-21 22:38 2581人阅读 评论(1) 收藏 举报


分类:

Eclipse(15)


版权声明:本文为博主原创文章,未经博主允许不得转载。

使用eclipse很长时间了,但对于eclipse中各种project之间的区别还是很不清楚。

上网想找些资料几乎找不到,关于java project和web project之间的区别,一般只是从用途上

认识,我想知道的是:eclipse是怎么认识这些工程的区别的?

不求甚解的结果其实很严重,我到现在还搞不明白他们之间的区别,遇到问题也无从下手。

相信下面的问题大家都遇到过:

tomcat project与dynamic web project的区别是什么?

为什么我倒入一个web 工程eclipse不认识?

使用server插件的命令Add and Remove就是加不进去?

为了研究这些project的区别,我先各建立一个空工程,看看它的配置文件到底哪里不一样。

java project就不用说了,这个你也不会有问题。

1.首先我使用server添加dynamic web project,这个可以添加。

2.然后用server添加static web project,不可以。

3,看看配置文件哪里不一样。

进入.settings文件夹

.jsdtscope文件,2个工程都有,内容也一样。

org.eclipse.jdt.core.prefs文件dynamic有,static没有。如下:

[html] view
plain copy

#Tue Mar 20 17:40:59 CST 2012

eclipse.preferences.version=1

org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled

org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6

org.eclipse.jdt.core.compiler.compliance=1.6

org.eclipse.jdt.core.compiler.problem.assertIdentifier=error

org.eclipse.jdt.core.compiler.problem.enumIdentifier=error

org.eclipse.jdt.core.compiler.source=1.6

看看里面的名字,其实是定义了jdk的版本,应该不是主要区别。

再看org.eclipse.wst.common.component文件,2个都有。

dynamic如下:

[html] view
plain copy

<?xml version="1.0" encoding="UTF-8"?>

<project-modules id="moduleCoreId" project-version="1.5.0">

<wb-module deploy-name="ddw">

<wb-resource deploy-path="/" source-path="/WebContent"/>

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>

<property name="context-root" value="ddw"/>

<property name="java-output-path" value="/ddw/build/classes"/>

</wb-module>

</project-modules>

static如下:

[html] view
plain copy

<?xml version="1.0" encoding="UTF-8"?>

<project-modules id="moduleCoreId" project-version="1.5.0">

<wb-module deploy-name="jingttt">

<wb-resource deploy-path="/" source-path="/WebContent"/>

<property name="context-root" value="jingttt"/>

</wb-module>

</project-modules>

这样我们应该猜出一些功能(下面是自己猜的,不准)

<wb-module deploy-name="ddw">定义了工程的名称

<wb-resource deploy-path="/" source-path="/WebContent"/>

定义了把工程中/WebContent下的文件发布到根目录"/"下面,在服务器地址后加一个"/"就等于

工程中"/WebContent"下的路径,这样就建立了对应关系。

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>

同样,把工程目录"/src"下的文件发布到"/WEB-INF/classes"(当然这里肯定是把编译过后的class文件发布过去,而不是源文件)

<property name="context-root" value="ddw"/>

定义了工程的根目录。

<property name="java-output-path" value="/ddw/build/classes"/>

定义了把工程编译后的class文件放到这个路径下。和上面<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>不同,

这个指你在eclipse建立工程的实际路径(即workSpace下的路径),而上面那个wb-resource其实在tomcat路径下说的。

即当你把工程发布到tomcat服务器下的路径。

从这里我们一概看出dynamic web project和static web project的一些区别了吧。

个中体会自己想吧, 本人水平不高,怕误人子弟。

/////////////

在看org.eclipse.wst.common.project.facet.core.xml文件,这个很重要,

以前有些问题网上也有说改这个文件的,问题是可以解决,原因却不清楚,现在看看吧:

dynamic

[html] view
plain copy

<?xml version="1.0" encoding="UTF-8"?>

<faceted-project>

<runtime name="Apache Tomcat v6.0.35forswing"/>

<fixed facet="wst.jsdt.web"/>

<fixed facet="java"/>

<fixed facet="jst.web"/>

<installed facet="java" version="1.6"/>

<installed facet="jst.web" version="2.5"/>

<installed facet="wst.jsdt.web" version="1.0"/>

</faceted-project>

static :

[html] view
plain copy

<?xml version="1.0" encoding="UTF-8"?>

<faceted-project>

<fixed facet="wst.jsdt.web"/>

<fixed facet="wst.web"/>

<installed facet="wst.web" version="1.0"/>

<installed facet="wst.jsdt.web" version="1.0"/>

</faceted-project>

本人猜测:

<runtime name="Apache Tomcat v6.0.35forswing"/>是定义发布到那个服务器,

因为我把tomca的文件夹改了名字t叫Apache Tomcat v6.0.35forswing,

一般不改就是Apache Tomcat v6.0.35。所以这里应该就是tomcat文件夹(根目录)的名字。

<fixed facet="wst.web"/>

<installed facet="wst.web" version="1.0"/>

<installed facet="wst.jsdt.web" version="1.0"/>

这3个都有,也看不出区别,过。

<fixed facet="jst.web"/>

这个dinamic有,

我把它加进到static中去,

没发现有啥反应,工程图标也没变,server还是加不进去。

再看<installed facet="jst.web" version="2.5"/>,这个只有dinamic有,

把它加进static。

工程图标还是没变,但是server可以加进去了!

这说明,eclipse是根据这个属性来判断两者之间的区别的。

我在引入一个web project(这个事用myeclipse建立并导出的),

引入后,server加不进去,协商这个属性后就可以了!

可见,这个属性就是eclipse认识web project的关键。

以前我也遇到过这个属性值是3.0的时候也会出问题,改成2.5就可以了。

既然这个值这么有用,大家不妨比较不同工程的这个值有什么区别。

这个文件不太好猜但很重要,呵呵。

org.eclipse.wst.jsdt.ui.superType.container这个里面就一行:

org.eclipse.wst.jsdt.launching.baseBrowserLibrary不知干嘛用的,应该是eclipse启动工程的入口吧。

org.eclipse.wst.jsdt.ui.superType.name这个文件也只有一行:

Window应该是定义了eclipse的Window版本。

至此这两个工程的区别,我们有了个比较靠谱的认识。

当你的工程server不认识的时候,你可以去看看org.eclipse.wst.common.project.facet.core.xml

现在再看看tomcat工程。

tomcat工程也是web project,但为什么单单出现了一个tomcat工程?

很不理解,我个人认为是因为有tomcat插件的原因!

因为tomcat插件可以配置一些属性管理工程的启动,比如:

在eclipse中的window---preference---tomcat页面中,

我们可以配置tomcat的版本,路径,以及管理工程的方式(2种server.xml和context files)

所以如果我们建立一个tomcat project,它里面没有.settings文件夹!!!

只有.tomcatplugin文件。因为工程的配置都在这个文件中了,然后交给tomcat插件去处理。

现在我们看看内容:

[html] view
plain copy

<?xml version="1.0" encoding="UTF-8"?>

<tomcatProjectProperties>

<rootDir>/</rootDir>

<exportSource>false</exportSource>

<reloadable>true</reloadable>

<redirectLogger>false</redirectLogger>

<updateXml>true</updateXml>

<warLocation></warLocation>

<extraInfo></extraInfo>

<webPath>/tommm</webPath>

</tomcatProjectProperties>

下面猜猜看:

<rootDir>/</rootDir>定义了工程根路径的标志(跟<wb-resource deploy-path="/" source-path="/WebContent"/>很相似)

<exportSource>false</exportSource>是否导出源文件

<reloadable>true</reloadable>是否重新加载,应该是你改了代码,它自己帮你发布,然后再启动。

不像myeclipse需要你点那个发布按钮。

<webPath>/tommm</webPath>这个定义工程名称和根路径。

/////////////////////////////////////

下面我们看看server这个组件,很多人在用,那它的原理到底是什么呢?

在新建一个server后,eclipse出现一个文件夹Servers。

看看内容:

.settings文件夹下有个org.eclipse.wst.server.core.prefs内容如下:

#Tue Mar 20 17:38:45 CST 2012

org.eclipse.wst.server.core.isServerProject=true

eclipse.preferences.version=1

我想应该是定义了server的一些参数和入口

文件夹Apache Tomcat v6.0.35forswing at localhost-config

前边Apache Tomcat v6.0.35forswing at localhost是我的tomcat的别名,在新建server起的。

config表示对这个tomcat的参数进行设置

现在主要说重要的文件:

server.xml

这个大家很熟悉吧,在tomcat路径下的conf下就有这个文件。

我先把刚才建的工程价进去,看看内容f发生了变化,如下:

[html] view
plain copy

<?xml version="1.0" encoding="UTF-8"?>

<!--

Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements. See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the "License"); you may not use this file except in compliance with

the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

--><!-- Note: A "Server" is not itself a "Container", so you may not

define subcomponents such as "Valves" at this level.

Documentation at /docs/config/server.html

--><Server port="8005" shutdown="SHUTDOWN">

<!--APR library loader. Documentation at /docs/apr.html -->

<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>

<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->

<Listener className="org.apache.catalina.core.JasperListener"/>

<!-- Prevent memory leaks due to use of particular java/javax APIs-->

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->

<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<!-- Global JNDI resources

Documentation at /docs/jndi-resources-howto.html

-->

<GlobalNamingResources>

<!-- Editable user database that can also be used by

UserDatabaseRealm to authenticate users

-->

<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share

a single "Container" Note: A "Service" is not itself a "Container",

so you may not define subcomponents such as "Valves" at this level.

Documentation at /docs/config/service.html

-->

<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->

<!--

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

maxThreads="150" minSpareThreads="4"/>

-->

<!-- A "Connector" represents an endpoint by which requests are received

and responses are returned. Documentation at :

Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)

Java AJP Connector: /docs/config/ajp.html

APR (HTTP/AJP) Connector: /docs/apr.html

Define a non-SSL HTTP/1.1 Connector on port 8080

-->

<Connector connectionTimeout="20000" port="8081" protocol="HTTP/1.1" redirectPort="8443"/>

<!-- A "Connector" using the shared thread pool-->

<!--

<Connector executor="tomcatThreadPool"

port="8080" protocol="HTTP/1.1"

connectionTimeout="20000"

redirectPort="8443" />

-->

<!-- Define a SSL HTTP/1.1 Connector on port 8443

This connector uses the JSSE configuration, when using APR, the

connector should be using the OpenSSL style configuration

described in the APR documentation -->

<!--

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

maxThreads="150" scheme="https" secure="true"

clientAuth="false" sslProtocol="TLS" />

-->

<!-- Define an AJP 1.3 Connector on port 8009 -->

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>

<!-- An Engine represents the entry point (within Catalina) that processes

every request. The Engine implementation for Tomcat stand alone

analyzes the HTTP headers included with the request, and passes them

on to the appropriate Host (virtual host).

Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :

<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

-->

<Engine defaultHost="localhost" name="Catalina">

<!--For clustering, please take a look at documentation at:

/docs/cluster-howto.html (simple how to)

/docs/config/cluster.html (reference documentation) -->

<!--

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

-->

<!-- The request dumper valve dumps useful debugging information about

the request and response data received and sent by Tomcat.

Documentation at: /docs/config/valve.html -->

<!--

<Valve className="org.apache.catalina.valves.RequestDumperValve"/>

-->

<!-- This Realm uses the UserDatabase configured in the global JNDI

resources under the key "UserDatabase". Any edits

that are performed against this UserDatabase are immediately

available for use by the Realm. -->

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

<!-- Define the default virtual host

Note: XML Schema validation will not work with Xerces 2.2.

-->

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">

<!-- SingleSignOn valve, share authentication between web applications

Documentation at: /docs/config/valve.html -->

<!--

<Valve className="org.apache.catalina.authenticator.SingleSignOn" />

-->

<!-- Access log processes all example.

Documentation at: /docs/config/valve.html -->

<!--

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

-->

<Context docBase="ddw" path="/ddw" reloadable="true" source="org.eclipse.jst.jee.server:ddw"/></Host>

</Engine>

</Service>

</Server>

我加的工程被写到了这里:

<Context docBase="ddw" path="/ddw" reloadable="true" source="org.eclipse.jst.jee.server:ddw"/>

可见server组件就是使用了Servers.xml发布方式,另一种是Context files。

至于这两种发布方式的区别是什么,我就不说了,网上一大堆。

当我们使用server发布的时候,再去tomcat路径下看看,果然这个文件应经改成我们在eclipse中的这个了。

其实就是在你发布的时候,它把这个文件覆盖tomcat下的那个文件,这和你自己手写一个这样的文件

然后覆盖tomcat那个是一样的道理。server其实就干了这些而已,不用它,你照样可以。

////////////////////////////////////

到此为止,我们应该有个浅显的认识,这些配置文件说白了就是管理工程的编译,发布。

它需要知道一些参数,比如你放工程的根路径,发布到哪个服务器,服务器的根路径、名称,

这个工程中的哪个路径对应服务器下的哪个路径,编译的class放在哪?发布的时候有又到哪?

工程是不是web工程?等等。

eclipse是个很好的工具,只是没有myeclipse做的那么人性化,功能强化。所以有些基本的

配置还是需要开发人员了解一些,不然总是运到问题糊里糊涂,解决问题也是看网上别人怎么做,

解决了问题也只是不知道为什么。也许这次管用,下次就不管用了。问题还是需要追本溯源。

只是这些知识网上几乎没有,我本人知识在猜测一些配置的功能,大家共勉吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: