Eclipse IDE internal project representaion - eclipse

Currently I'm trying to write a tool for migration from Eclipse IDE to Intellij Idea specifically for my project.
For now, the main question is how and where Eclipse store project information (i.e. libraries, dependencies between app modules and so on) internally.
P.S.
The Intellij's migration tool does not work for my project.
Update:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry excluding="generated/" kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Everything that eclipse keeps on your project is stored in the .settings folder (containing a.o. .project and .classpath).
But unless you have some very specific setup you should be able to import your project into IntelliJ without any hassle. Even if it's not, I would expect that setting up the project manually in IntelliJ will be a lot faster than writing a tool for it.

Related

How to convert eclipse java projects into groovy projects?

I have set of ten to twelve native java projects checked out from svn. Eventually I am considering to convert all the code into groovy. I am only concentrating on these two steps first:
1) Convert java projects to Groovy projects
2) Change the extensions of all the 10,000 odd files in all the projects to .groovy.
So I want to know if eclipse can provide me some help with these two steps (via UI) without me having to change all the .classpath entries or .project entries.
PS: I already have the groovy plugin installed
Are the java projects also Maven projects? That creates a bit more confusion, but is workable. You should be able start by editing the .classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/someDirectory"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
This is for a Maven and Groovy project. You can leave out the Maven line if it is not needed. Eclipse doesn't seem to like Maven+Groovy projects, so you will have to fix the .classpath again after you import it, but it won't change it again after that.
I'd recommend using a batch file for the renames (or a C# program, if you have VS installed, too).
I found this example: https://superuser.com/questions/205083/which-command-can-i-use-to-recursively-rename-or-move-a-file-in-windows
For loops are a bit odd in batch files, but they work nicely.
I think that would get you going. Start with the smallest project, of course!

Multiple maven projects in eclipse Indigo

I have a multiple maven project like this:
root/
----war
----jar1
----jar2
----jar3
The war use jar1, jar2 and jar3
When I run a "mvn clean install", the compiled war is good and work fine in my server (jboss).
When I run a "mvn eclipse:eclipse" to generate my eclipse configuration, the build works but when I import my projects in eclipse (Indigo) and I publish my war in my server, jar1, jar2, jar3 are not publish.
In the war build path configuration, jar1, jar2, jar3 are well configured.
But when I look at the deployment assembly for the war project, I have the next error:
Here is my generated .classpath file for the war project:
<classpath>
<classpathentry kind="src" path="src/main/java" including="**/*.java"/>
<classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="var" path="M2_REPO/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13.jar" sourcepath="M2_REPO/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13-sources.jar">
<attributes>
<attribute value="jar:file:/Users/Kiva/java/repoMaven/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/javax/faces/jsf-impl/1.2_13/jsf-impl-1.2_13.jar" sourcepath="M2_REPO/javax/faces/jsf-impl/1.2_13/jsf-impl-1.2_13-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar" sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/servlet/jstl/1.2/jstl-1.2.jar" sourcepath="M2_REPO/javax/servlet/jstl/1.2/jstl-1.2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/el/el-api/1.0/el-api-1.0.jar" sourcepath="M2_REPO/javax/el/el-api/1.0/el-api-1.0-sources.jar">
<attributes>
<attribute value="/WEB-INF/lib" name="org.eclipse.jst.component.dependency"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/jar1"/>
<classpathentry kind="src" path="/jar2"/>
<classpathentry kind="src" path="/jar3"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.0.5.RELEASE/spring-core-3.0.5.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-core/3.0.5.RELEASE/spring-core-3.0.5.RELEASE-sources.jar">
<attributes>
<attribute value="/WEB-INF/lib" name="org.eclipse.jst.component.dependency"/>
</attributes>
</classpathentry>
</classpath>
Here is my eclipse plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
I don't understand why it's wrong in my plugin configuration and why eclipse doesn't find jars.
Thanks for your help.
The most important thing in that case is: Don't use eclipse:eclipse anymore use the m2e plugin instead in relationship with Maven. Just simply do an import of the project. You should add m2e for wtp via Eclipse Marketplace. After that you should be able to deploy the war to the server.
You could give a try to Eclipse Multi-project Import/Export. I think it will cover your needs.
I have found the problem.
The jboss tools maven support plugin (install with jboss tools) break the link between projects. Uninstalling it will solve the problem.
It's possible to uninstall just the maven support and keep the rest ;)

How to instruct Eclipse to record relative paths of the external jars?

Here is my .classpath file, after I have added two more external jars (org.restlet.ext.simple.jar and org.simpleframework.jar):
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.restlet.ext.jackson.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
<attributes>
<attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/ext/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.restlet.ext.ssl.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
<attributes>
<attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/ext/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.restlet.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
<attributes>
<attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/api"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.jsslutils_1.0/org.jsslutils.jar"/>
<classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.codehaus.jackson_1.4/org.codehaus.jackson.core.jar"/>
<classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.codehaus.jackson_1.4/org.codehaus.jackson.mapper.jar"/>
<classpathentry kind="lib" path="../3rd_party/guice-3.0/aopalliance.jar"/>
<classpathentry kind="lib" path="../3rd_party/guice-3.0/guice-3.0.jar"/>
<classpathentry kind="lib" path="../3rd_party/guice-3.0/javax.inject.jar"/>
<classpathentry kind="lib" path="C:/dev/poc/3rd_party/restlet-jse-2.0.10/lib/org.restlet.ext.simple.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
<attributes>
<attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/ext/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/dev/poc/3rd_party/restlet-jse-2.0.10/lib/org.simpleframework_4.1/org.simpleframework.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Notice that they have been added with absolute paths, unlike other entries which are with relative ones, but only because I manually edit this file each time new external jars are added.
My question is can I somehow tell Eclipse to use relative paths of newly added external jars?
Thanks.
One solution is to not use external jars, but to put your jars into a project, and then use Add Jar(s) instead of Add External Jar(s).
This makes sense from the point of view of source control, you can add/remove dependencies as you need them. It also means that when you update one jar for a separate project, it'll not affect this one.
We've done this in the past, we had a single project which contained all of the jars, which were referred to in the build paths of other projects.
But now we use maven, so we don't need to do that any more.
In eclipse, right-click the project, choose Properties, then Java Build Path, Libraries tab and select "Add Jars"... this will add it with a relative path. "Add External JARs" adds the jar with an absolute path which is not what you want.
If your paths are relative to your Eclipse installation, declare them using the “Add Variable…” button (in [Project] → Properties → Java Build Path → Libraries). There you should be offered a variable called ECLIPSE_HOME, which you can then Extend. This will produce a „kind=var“ entry in your .classpath(rather than a „kind=lib“).
<classpathentry kind="var" path="ECLIPSE_HOME/...
If your paths are relative to somewhere else you can declare your own variables (Configure variables). This way, when your workspace changes or someone makes a copy of it you just need to update these variables. This is often clearer than having true relative paths starting with one or two dots.
Please note that Eclipse relative paths should begin with a single dot.
Instead of
<classpathentry kind="lib" path="../3rd_party/example.jar"/>
You need to use
<classpathentry kind="lib" path="./../3rd_party/example.jar"/>
The first method might sometimes work, but the second method works always.
This is very confusing because you might have 5 entries in classpath that work with the ".." at the beginning and the others won't work with it.
Change all references to begin with the single dot first.

importing a project from Perforce Eclipse Plugin as Java Project

I am trying import a project from Perforce workspace in Eclipse. It is importing it (fetching the files into java package hierarchy) but the problem is it is not importing as "Java project". so i can't edit the "Build path" or there is no classpath or something.
Any idea?
You need to make sure to put Eclipse metadata files into your source control system. All files starting with . in the project root along with entire .settings directory need to get checked in along with your source. If you don't do that, Eclipse will loose all knowledge of the type of projects that it is and how it supposed to be configured.
If your Project in Perforce do not contain files of regular Eclipse java projects you can create another project with Java Nature. Keep Project empty.
File > New > Java Project
It will create for you following files.
.classpath
.project
.settings/org.eclipse.jdt.core.prefs
With this empty project by default your source folder is set to "src".
Now you have to copy first two files mentioned above to your Perforce workspace directory. Close and reopen project.
If you still have issues please check file .project. It should contain Nature section.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Dev-Project_03_04_2016</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Now Check your .classpath File. Since you copied it from blank project it contains something like:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
You need to remove this default default "src" folder and add your source folders, of course if you wont do development in eclipse you do not need all this. If you did everything correctly, andded also JUnit Nature you wil get something as follows:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="bb/apps/911access-zip/components/911emergencydriver-ejb/src/main/java"/>
<classpathentry kind="src" path="bb/apps/911access-zip/components/911accessmodel-ejb/src/main/java"/>
<classpathentry kind="src" path="bb/apps/911access-zip/components/911accessplugin-ejb/src/main/java"/>
<classpathentry kind="src" path="bb/apps/911access-zip/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>

ClassNotFoundException when running a Spring + Maven2 project on Tomcat 6 from within Eclipse 3.5

When trying to launch a Web project from within Eclipse I get:
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3877)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Project started to fail when I switched to Fedora 12 x64. The project worked on WinXP with same configuration.
Googling around I found posts claiming that going to Project Properties -> Java EE Module Dependencies and checking the Maven Dependencies box fixes the issue. Sadly it didn't worked for me.
I'm using Spring 2.5.6, Maven2, Eclipse 3.5 (with the m2e 0.10.0 plugin), Tomcat 6 and Java 6 running on Fedora 12 x64.
Has anyone seen this problem?
In case it helps here is my .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/gpb"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.iam.jdt.core.mavenClasspathContainer">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</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="output" path="target/classes"/>
</classpath>
Update: I don't have any problems building or running the project outside Eclipse.
You seem to have both Eclipse IAM and M2Eclipse stuff in your .classpath. I would do some cleanup:
Use only one of these plugin (I suggest using M2Eclipse).
Delete your project from Eclipse's workspace, delete the .classpath and .project and Import the project as a Maven project again.
Update: To get WTP support with M2Eclipse, you need to install the Maven Integration for WTP from the m2eclipse Extras update site: http://download.eclipse.org/m2e-wtp/releases/ as illustrated below:
I had the same symptom with a different cause. I had to edit my .classpath file. The maven entry:
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
...was lacking the attributes tag shown here. When I added the attributes tag the problem went away. I'm very curious how to configure that in the eclipse ui.
Note that the steps to install the WTP integration have changed.
See: Maven/Tomcat Projects In Eclipse Indigo/3.7
From time to time, face with same problem.
For some strange reason, this problem could be fixed this way
1) Right mouse click on project Maven -> Disable Maven Dependencies
2) Right mouse click on project Maven -> Enable Maven Dependencies