There is no java resources folder in my eclipse maven project - java

In my eclipse maven project there is no java resources folder like this.
When I create my dynamic web application there is no java resources folder in it. I tick the Generate web.xml deployment descriptor at the end also but there is no Java resources folder. Can you resolve my problem?
This is my project explorer. Can you see there is no java resources folder.

Which eclipse version are you using? I am using the newest stable version and the tree node "java resources" does not appear. It might have been called like that in older eclipse versions but I am not sure. The important thing is though, that you should have a tree node for "src/main/resources" or at least a hierarchical structure like
src
main
resources
You can also compare your structure with a sample project which you can create from maven archetypes. Go to File > New > Project > Maven > Maven Project > Next > and select one of the sample archetypes like maven-archetype-webapp > enter an artifact name and finish. Now you can see how it should be displayed in eclipse correctly.

Related

converting a Webproject into maven project structure

I have the below Web project which is working fine. I wanted to change the structure of the project into a maven project structure.
So, I modified the project to as shown below(I created a new folder called webapp under src/main and I moved the contents of the folder WebContent into webapp and I deleted WebContent folder) Now the application doesn't work although I deploy it in the Tomcat Server. What is wrong in the below project structure . Please help me out
EDIT: I wanted a maven project structure as shown below which is a standard maven project structure
If you are using eclipse (which it looks like you are), you can use the M2Eclipse plugin, which will provide a "convert to maven" utility. Simply right click the project and go to configure -> convert to Maven.
https://www.eclipse.org/m2e/
The structure you are looking for can be defined at the time of project creation in the source directory screen. If you have an existing project you will need to add a new source folder.
To do so,
Add the folders to your project.
Right click on folder > build path > use as source folder.

Convert Java/Dynamic web project to maven project using Maven Command line

I want to convert a Java/Dynamic web project to a Maven project. I use Eclipse IDE to develop Java applications.
One of the straight forward options available to me is to use 'Convert to Maven project' in Eclipse. But there are situations where I cannot use that option since the Maven plugin doesn't work in some networks like my Work environment.
So I want to know a Maven command (on Command Line) that would help me convert my Eclipse-built Java Web App to a Maven project.
Thank you in advance, Happy learning.
The Eclipse feature "Convert to Maven Project" works on projects that already have an appropriate POM. A project that was initially created by Eclipse doesn't have that POM.
So what you must do, is simply create a POM with packaging type WAR, then put it into the root of the project.
You also have to take care of the source directories. The Maven standard way is to have all sources under these four directories:
src/main/java
src/main/resources
src/test/java
src/test/resources
Eclipse simply stores everything under src. So you either change your file and directory structure, or you change the appropriate <build> parameters in the POM. I suggest the former.
The "Convert to Maven Project" feature does more than adding the Maven nature to the Eclipse build settings. It also creates and configures the Eclipse project meta files (the files .project and .classpath and the folder .settings). Therefore I suggest to delete them first in your project directory, so Eclipse can start on a clean project.
Afterwards you simply can convert your project with the above mentioned feature. It should create the meta files, and - as it is a web project (packaging type WAR) - it also should add the appropriate natures that let Eclipse show the project as a web project.

Maven package structure changed after build Eclipse

I created a Maven project in Eclipse. Initially my package structure was like
-src/main/java
---com.package1
---com.package2
-src/main/resources
When I build the project successfully and got war deployed in tomcat, My project structure changed to
-src.main.java.com.package1
-src.main.java.com.package2
-src.main.resources
This is generating errors in Java class files in packages import declarations.
I want to restore my original project structure. I have m2eclipse plugin installed in Eclipse.
I also tried Maven>Update Project.. (I read somewhere on Stack Overflow that it will restore the original structure) but it is generating the following error
Failed while installing JAX-RS (REST Web Services) 1.1.
org.osgi.service.prefs.BackingStoreException: Resource /Workspace/ProjectName/.settings' does not exist.
Please help how I can restore my project structure back.
The following helped in my context:
Eclipse Luna (4.4.2) with Maven embedded
Multi module project where folder structure is
parent P
module A
module B
P is a normal Eclipse project while A and B are Maven projects
P is a closed, A and B are opened
the error happened in B with message Resource /P/B/.settings not available
After opening P again the error disappears and Project>Maven>Update Project... works fine.
It seems you have created the src/main/java and src/main/resources as normal folder. Just change them to source folder. It will work.
Steps
1.Go to src folder & Right Click
2.New->Others->Source Fokder
3.Then make the folder structure as /main/java & /main/resources
4.Then add the packages.

"Could not find or load main class" after removing Maven nature and files (pom.xml, target/) from an Eclipse Project

I accidentally converted my project to Maven by going to Configure > Convert to Maven Project. Now I want to undo this. I read that I need to right click Maven > Disable Maven Nature and that worked fine. However I want to totally remove Maven, so I deleted the pom.xml and the target folder. When I try to run my code now, I get the error:
Error: Could not find or load main class
So what am I missing? How do I revert from a Maven project to a non-Maven project?
When you convert a Java project to a Maven project in Eclipse, the Maven Integration for Eclipse (m2eclipse) configures the Java incremental compiler to put the compiled class files in the same location as Maven would put them, i.e. target/classes.
So when you remove the Maven nature and delete the target folder, you now also have deleted the compiled class files and your project can no longer run. AFAIK, the incremental compiler doesn't detect when you remove its output files, so you need to trigger a rebuild by cleaning the project (Project > Clean...)
This will fix the problem that you can not launch your project, but may re-create a target folder. If you also want this to be "fixed", you can switch back to some other folder name for the binaries, e.g. bin, in the project's Java Build Path configuration on the Source tab.
Is it basically a Maven project, i.e., do you have and maintain it through a pom.xml? Then my suggestion is to delete the project in Eclipse but keep the files on the disk (i.e., it removes it from the workspace). Then, run a simple mvn eclipse:clean eclipse:eclipse which creates a simple Java project without the Maven nature based on the POM (so the libraries are linked and the source/output directories are set up correctly - this may solve your ClassNotFoundError).
If it's a simple Java project, I would advise deleting it from the workspace, removing the .classpath and .project files and importing it again with the Create a Java project with existing sources wizard.
Either way, make a backup of your project before you start doing anything :-)

Linked scr to new project build in Eclipse

I am using Eclipse 3.8.1. I have one project with sources and one which I build.
--ProjectSRC (from svn)
-- src
--main.java
--Project_build (builded project using ProjectSRC files)
--src
--main.java
--build
main.class
I have svn project and I downloaded locally these files but I want to make a new project from them. I am trying to link sources but when I change something in eclipse for example in file main.java in Project_build , another project in eclipse which is linked with the svn do not see changes of this file, so I have to copy changes manually, or to build the project with sources. And if I do that, when I synchronize with the repository there are a lot of build directories and .project files which every time I have to unchecked.
So how to connect sources from one svn project and to create new with them and when a change become to be reflected on the two places, through Eclipse?

Categories

Resources