Eclipse or IDE integrated with Eclipse .project and .classpath files

Recently, I got a very interesting task. In our daily work, we use Liferay, Liferay uses Ant to create projects. All projects created by Liferay is basic not targeted to our client. So when we create the project, we still need to change or add something to meet our requirements like package name. Instead of changing those standard again and again, we can write ant script to build our own project.

It was successfully built, but I can't import the project into IDE, the missing file is .project file. If you copy one from the other project, change the project name, then you can import the project. Then you'll find, there's no JAR Library or other dependencies bound to the project, this is of course because it lacks of .classpath file. All dependencies are defined in .classpath file. The classpath file is also influenced by your IDE plugins.

Here is an sample of my .project and .classpath file!

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>@hook.name@</name>
	<comment>@hook.display.name@</comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.wst.common.project.facet.core.builder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.wst.validation.validationbuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.zeroturnaround.eclipse.rebelXmlBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.m2e.core.maven2Builder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
	</natures>
</projectDescription>

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="docroot/WEB-INF/src"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/Liferay v6.1 EE (Tomcat 7) JRE (1)">
		<attributes>
			<attribute name="owner.project.facets" value="java"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.liferay.studio.eclipse.server.ee.tomcat.runtimeClasspathProvider/Liferay v6.1 EE (Tomcat 7)">
		<attributes>
			<attribute name="owner.project.facets" value="jst.web"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
	<classpathentry kind="con" path="com.liferay.ide.eclipse.server.plugin.container/hook">
		<attributes>
			<attribute name="org.eclipse.jst.component.nondependency" value=""/>
		</attributes>
	</classpathentry>
	<classpathentry kind="output" path="docroot/WEB-INF/classes"/>
</classpath>

Appendix: I searched online, also put others explain here:

Basically, .project files store project-settings, such as builder and project nature settings, while .classpath files define the classpath to use during running. The classpath files contains src and target entries that correspond with folders in the project; the con entries are used to describe some kind of "virtual" entries, such as the JVM libs or in case of eclipse plug-ins dependencies (normal Java project dependencies are displayed differently, using a special src entry).


你可能感兴趣的:(eclipse,eclipse,ide,ide,.project,.classpath)