package structure is changed in eclipse - eclipse

I have a dynamic web project which is perfectly working . Then i tried to change it to mvn web project using mvn eclipse:eclipse -Dwtpversion=2.0 command then my package structure is changed . main.java packages added to my package . I tried to change in .classpath file by adding
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
but project package is not changing.
Below is my changed project structure . How can i bring it back to normal(remove main.java from package)
Thanks in advance
EDIT:
when i tried to edit source folder it is showing following error:

You have to change the source folders in your project configuration under Java build path

Related

eclipse sts gradle multimodule project problem

Using Eclipse STS 4.10 / linux .
I have a multimodule project like :
-rootFolder
-web (web app)
-dataservice (services, domain logic)
-datadef (model,repositories)
web has dataservice as a dependency
build.gradle shows:
dependencies {
compile project(':dataservice')
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
///
}
dataservice has datadef as a dependency
build.gradle shows:
dependencies {
compile project(':datadef')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
///
}
What I cannot achieve is datadef-1.0.0-SNAPSHOT.jar being included in dataservice-1.0.0-SNAPSHOT.jar file . Both are getting included in web.app though.
Sometimes eclipse "looses" reference on dataservice the datadef project and treat anything from datadef as an error.
Pasting dataservice project .classpath file. It shows the dependency on datadef.
<classpath>
<classpathentry kind="output" path="bin/default"/>
<classpathentry output="bin/main" kind="src" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry output="bin/main" kind="src" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry output="bin/test" kind="src" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="src" path="/datadef">
...```
Thank you.

Best way to configure Eclipse to work with Maven projects and Java modules

What's the best way to use current Eclipse version (2020.12) + traditional Maven projects (like maven-archetype-quickstart) with main and test sources in the same project + Java (9+) modules? To be more exact, how to configure junit test dependencies so that Eclipse does not show compilation errors.
I'd appreciate if maven-archetype-quickstart with module-info.java and Eclipse configuration could be attached too.
I got it working. After adding module-info.java, error appears:
Build path configuration remains:
"Update Maven Project" has to be executed in Eclipse. Then Eclipse's Maven plugin updates .classpath by removing <attribute name="module" value="true"/> from
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
which results in this "Java Build Path" in the UI:

Is there a way to make Eclipse Package Explorer show output directory content?

I hate having to switch to the Navigator view just to see what was built. For example, if I want to see if my *.properties files getting moved, etc.
I tried removing all of the Filters... from Package Explorer's dropdown menu, but it is still not displaying the contents of my "target" folder.
Am I missing something?
I attached my .classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
As far as I know, only the Project Explorer view (not Package Explorer) can display output folders.
In that (Project) view, you should see a small down arrow at the top right of the view:
Choose the option Customize View option.
Uncheck the 'Java output folders' option in the filters list.
You would see the same process to see .class files produced by a classic java build.

Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?

The sources are downloaded in the Gradle cache and the classpath-entries for the source files looks ok, but Eclipse does not show the source files for 3rd party libs.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin/main"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry output="bin/test" kind="src" path="src/test/java"/>
<classpathentry output="bin/test" kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container" exported="true"/>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/source/bc9c347358c5d59998b27e8a13c75106c3d0696/spring-webmvc-3.1.2.RELEASE-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/jar/e02f3e5aa91c8caa37b2e9b780229d27e76c0f2e/spring-webmvc-3.1.2.RELEASE.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/source/19e4dedbb956cdc3bb1d34d61a351229b653029a/spring-data-jpa-1.2.0.BUILD-SNAPSHOT-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/jar/2a3cfc2ea0b2c8d87f32166e16bb56e1f092568b/spring-data-jpa-1.2.0.BUILD-SNAPSHOT.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/source/49e8d929d835d4ba4556ba9d138488ecc083a794/spring-security-web-3.1.2.RELEASE-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/jar/e43e7683289f08c1e073564a94e6f26298ec4f59/spring-security-web-3.1.2.RELEASE.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/source/7a561191db2203550fbfa40d534d4997624cd369/validation-api-1.0.0.GA-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/jar/b6bd7f9d78f6fdaa3c37dae18a4bd298915f328e/validation-api-1.0.0.GA.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
</classpath>
That's a weird behavior in Eclipse with the generated .classpath-file. Just put the 'Web App Libraries' entry at the bottom of your classpath file (-> Java Build Path -> Order and Export).
The best solution is to enhance your gradle.build file (then you don't need to reorder your build path each time you generate the classpath file via gradle):
...
eclipse.classpath.file {
// Classpath entry for Eclipse which changes the order of classpathentries; otherwise no sources for 3rd party jars are shown
withXml { xml ->
def node = xml.asNode()
node.remove( node.find { it.#path == 'org.eclipse.jst.j2ee.internal.web.container' } )
node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])
}
}

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 ;)