Maven resource folder isn't created - maven

I'm using Eclipse Indigo with m2e plugin, and I've added to the build section of my pom.xml a resources tag. However the resource directory doesn't get created. I've also called Maven -> Update Project Configuration...
<build>
<finalName>...</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
What am I missing?

If the resources folder itself doesn't exist create the folder under the folder main. Then Right click the project, go to Maven -> Update Project. It worked for me.

It appears that you may not have created the maven project correctly. Perhaps you may have chosen an archetype, which does not do this correctly.
One possible way (which worked for me) is as follows:
When I do Create a new maven project, and choose Create a simple project (skip archetype selection, I do get the default folders created (src/main/java, src/main/resources, src/test/java, src/test/resources, along with the pom.xml).

As an alternative to creating a new project you could also have fixed the existing one by doing the following:
Do a non-destructive delete of the project from Eclipse i.e. do NOT check "Delete project contents on disk"
In the file system, remove the .settings/, .classpath, and .project files.
Also in the file system, add the resources folders under src/main and src/test.
In Eclipse, do an "Existing Maven Projects" import with the project's folder as the root.

This tag <resource>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
is not needed as this point because is the default resource folder maven looks for. Just need to add this
<resources>
<resource>
<directory>src/newDir/dir</directory>
</resource>
</resources>
at your pom.xml if you gonna use a different folder as a resource for your project.

You can create the folders in your file system and after that, you can change the .classpath file in the root of the project, next to the pom.xml
Just add something like:
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
After create the folders and update the .classpath you only have to refresh (F5) in Eclipse.
PS: I don't know if this depends of your maven version, check if it is similar to the other "classpathentry" that you have.

If you are getting only one folder inside Java Resources(ie,src/main/java),and if you are looking for other folders(src/main/resoures, src/test/java) then do the following steps:[Dont forget to configure Server(like Tomcate)]
1)Right click on your project
2)Build path
3)congigure build path
4)Libraries
5)Add library
6)Server Runtime
7)then Select your server(In my case i have selected Tomcat)
8)Finish

Every Maven Archetype has a different directory structure. See here the Maven website on the different available archetypes: https://maven.apache.org/archetypes/index.html
When choosing an Maven Archetype, you can follow the link above and click on the various archetypes and it will show you the directory structure that comes with each archetype. For example, the Maven Simple Project Archetype looks like this:
Maven Simple Project Archetype directory structure

This worked for me. ->
In Java Build Path tick both JRE System library and Maven Dependencies and click on Apply and close.

My Maven project was created without src/main/resource and src/test/resource. I tried the below steps :
Create New Maven Project-->On "New Maven Project" screen -->Tick the "Create a simple project(skip archetype selection)"-->Provide the Project name-->Click Finish
Now you can see the resuorce folders created.

if you're using intellij as your IDE, you can simply create the resources directory by right clicking the main folder in your project and attempt to make a new Directory, if you already don't have the resources Directory for your maven project, intellij has a suggestion for you to create it.

I cleaned my project and solved my problem this way.
Menu > Project > Clean...

Related

How to stop intellij-idea from marking profiles/dev as resource root?

My project structure is like this:
src
main
java
profiles
dev
prod
resources
the resources folder is my resource root, but every time I restart IDEA, the profiles/dev folder is ALSO marked as resource root. And when I debug the application, property files inside profile/dev is used instead of files inside the resources folder.
How do I stop this?
The root cause for this may be that your project is a Maven (or Gradle) project and the Maven (or Gradle) project configuration instructs IntelliJ to treat the profiles folder as a resources folder.
In a Maven pom.xml this might look like:
<build>
...
<resources>
<resource>
/path/to/profiles
<resource>
</resource>
</build>
If that's the root cause then your could change your pom.xml to prevent IntelliJ from treating the profiles folder as a resource.
Alternatively, you could explicitly mark this folder as excluded in the Project Structure dialog (though if the root cause is Maven or Gradle build configuration then this would be overriden the next time you reimport the project into IntelliJ) ...
Open File > Project Structure
Select Modules then select whichever module you want to configure
Select the profiles folder
Click on the Excluded button
From the docs:
Excluded roots
Files in excluded folders are ignored by code completion, navigation and inspection. That is why, when you exclude a folder that you don't need at the moment, you can increase the IDE performance.
Normally, compilation output folders are marked as excluded.
Apart from excluding the entire folders, you can also exclude specific files.
Here's a screenshot:

Unresolved plugin: 'org.apache.maven.plugins:maven-jar-plugin:2.4'

After I use IntelliJ IDEA to create a maven module, there is some problem in the Maven Projects view. And when my cursor hover on the maven project, i see this:
Project:
cn.itcast.babasport:parent:1.0-SNAPSHOT
Location:
/home/shuaidi/IdeaProjects/parent/pom.xml
Problems:
Unresolved plugin: 'org.apache.maven.plugins:maven-jar-plugin:2.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-compiler-plugin:3.1'
Unresolved plugin: 'org.apache.maven.plugins:maven-surefire-plugin:2.12.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-install-plugin:2.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-site-plugin:3.3'
This is my first time using IntelliJ IDEA, so I do these thing with a new installed IDEA and a new installed maven, and i just create a maven module and didn't do any other thing. I don't know why these problem appearance.
I just want to create a maven module without any problem.
ps:
this is all my pom file.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.itcast.babasport</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
This is a duplicate of Maven plugins can not be found in IntelliJ. The top answers there did not work for me, so I'll describe what I did.
I just put the needed plugins into my ~/.m2/repository. There are two ways that achieve that. Either download the files manually with mvn dependency:get, or (my preferred way) make the plugins a dependency in some (whichever) pom.xml and build that project.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<type>maven-plugin</type>
</dependency>
Now you can remove the dependencies. Then click "Reimport all Maven Projects" in Intellij (the blue circular arrows icon).
This issue seems completely harmless, but the squiggly lines are kind of infuriating, so I am glad I was able to get rid of them.
Instead of trying to install the plugin into your repository, actually delete it from your repository. It might have a corrupt or unsupported version that IJ cannot parse.
see https://stackoverflow.com/a/44883900/5093961
Change Maven home directory in Maven setting, and select supported Maven bundle version (Maven 2 or Maven 3), then apply setting. It's worked for me.
In my case same situation occurred because of different version exist in same system.
System have version 2.** and my project expect 3.** something
in such case, i use maven wrapper instead of maven to build project.
mvn clean install
instead of,
mvnw clean install
If you want this error to be gone without having to worry about all those xml files and copy pasting stuff just try the below solution
Note: This is manual way
In your InteliJ IDEA, go to search and type "Project Structure"
Search>Project Structure
or press:
Ctrl + Alt + Shift + S
Now go to Libraries under project settings
Project Settings>Libraries
Now look for red lined dependencies and click it
For example:
Click "Maven: javax:javaee-web-api:7.0"
Now look whether all three files are red lined
Example: Classes, Sources, JavaDocs
If any of the path under these names are redlined then go to that path and keep the folder open
For example: The path would look like this
Classes
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0.jar
Sources
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0-sources.jar
JavaDocs
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0-javadoc.jar
Now go to the folder as said above and keep it open
In my case its
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0
Now click this website
and search for the jar file
In my case it's:
javaee web api
Now click the link and select the version in next page
In my case it's:
7.0
Now find the "Files" row which will be between "Date" and "Repositories"
In the Files row, click View All
It will open a page like This
In that page download the missing files(classes,source,javadoc)
It will look like this
javaee-web-api-7.0.jar
javaee-web-api-7.0-sources.jar
javaee-web-api-7.0-javadoc.jar
Download all three and put it into the folder which I said you to keep open
Now open your project in inteliJ IDEA and build your project and open the "project structure" as instructed above and check it, the redlined files will have no redlines anymore.
This may seem easy but if there are more files which generates errors then you will have to do this process multiple times and download the missing files.
In that case the above solutions may help...
Check idea.log for errors related to Maven importing, it could be
a network issue with localhost
invalid VM options for Maven VM (too large heap or a typo in VM options)
Maven process failing for some other reason (like the recent Nvidia driver update has caused Java crashes).
I just solved this problem few minutes ago and this is what I figured and my solution:
The reason intellij is popping up with those errors is because the plugin files for those failed plugins in the ".m2" directory are not properly downloaded or they are broken.
This is what I did:
I went to "C:\Users\IYANU.m2\repository\org\apache\maven\plugins" folder. You will see that the name of the plugins matches the ones giving errors in IntelliJ
One after the other, in each plugin folder, I checked for the version giving error in IntelliJ then delete the version folder. Like for "maven-jar-plugin", the version in 2.4, delete the 2.4 folder in the maven-jar-plugin folder.
After deleting, go back to IntelliJ and reload your maven project. Make sure there is an internet connection. This will make IntelliJ properly download the plugin and the error won't pop up for that particular plugin again.
Repeat it for the other plugins giving error
Thank me later
This worked for me:
Download 'maven-jar-plugin:2.4.jar' from maven-repository (https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin/2.4)
Paste the downloaded 'maven-jar-plugin:2.4.jar' in the local PC's mvn-repository ('C:\Users\[user-name].m2\repository\org\apache\maven\plugins\maven-jar-plugin\2.4' folder)
Wait for IntelliJ to pick up the change
All done!

Extract current folder name within maven pom.xml file

I am looking for a way to dynamically extract the current folder name within maven pom.xml file.
For Example:
if the pom.xml file is at /home/jenkins/workspace/bdms-ci/bdms-bcr/pom.xml
then bdms-bcr is the current folder.
See a code snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<testClassesDirectory>../../bdms-ci-improve/${project.basedir}/target/test-classes</testClassesDirectory>
<classesDirectory>../../bdms-ci-improve/${project.basedir}/target/classes</classesDirectory>
</configuration>
</plugin>
${project.basedir} will bring the full path which is not good since only the current folder is needed.
I tried to work with MavenProject class from the maven api document:
${project.file.parentFile.name} or ${project.file.name}, but it didn't work.
remember it is maven multi project and everything has to be dynamically.
The whole issue is for jenkins ci build which use parallel-test-executor plugin. I would like to compile once in the main job and then all the other test execute jobs will will only test by looking into the compiled code.
Using maven 3.2.3
#guymi,
Seems like you should be able to simply use ${project.artifactId} or perhaps ${parent.artifactId}.
EDIT
Or does your artifactId name disagree with the directory it's stored in?
If so, that's possible but not good practice and should be avoided.
It is not possible to do it. simple as that.
A workaround solution is by using artifactId with the same name as folder name. then you can do:
../../bdms-ci-improve/${project.artifactId}/target/test-classes</testClassesDirectory>

How to edit the directory structure in Maven?

I am using Maven project, when i create the Maven module of jar packaging, maven auto generates directory structue as src/main/java, src/main/resources, src/test/java and src/test/resources. Can I edit the above names as per my wish? Can I add new folders to the same parent? Also when i googled, I came to know abt super POM, can anybody suggest how to edit the same with the custom directory structure. I have configured sonatype maven to my eclipse from the link http://m2eclipse.sonatype.org/sites/m2e
Assuming you have a good reason to do this, you can rename the folders and indicate to maven what is the edited one by specifying the appropriate properties/sections in pom.xml of your project. I suppose m2e will pick up the changes once made to the pom.
The relevant section in your case would be (from the superpom)
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
If you want to add additional source folders or resources (not subfolders), then you can use build helper maven plugin. Again, not sure what m2e will do.

Intellij: jboss-ejb3.xml entry keeps disappearing from ${PROJECT_DIR}/.idea/artifacts/XXX_war_exploded.xml

Why is it that although I've
set the proper path to the JBoss EJB deployment descriptor in my project's EJB facet
added jboss-ejb3.xml to Intellij's artifact Patrac-web:war exploded's <output root>/WEB-INF
that any time I make the simplest change to pom.xml Intellij removes the following entry from ${PROJECT_DIR}/.idea/artifacts/Patrac_web_war_exploded.xml:
<element id="file-copy" path="$PROJECT_DIR$/Patrac-ejb/src/main/resources/META-INF/jboss-ejb3.xml" />
and, as a result, jboss-ejb3.xml does not get copied to the target directory?
It's as though each time I make a change to pom.xml Intellij "reloads" the deployment configuration using the POM to override what settings I make within the IDE. Perhaps because I have no entry in my pom.xml for copying jboss-ejb3.xml from source directory to target directory the settings I make in Intellij IDE keep disappearing whenever Intellij "reloads." Pure conjecture on my part, but this is what seems to be happening.
If so, what change do I need to make to pom.xml in order to make this stop happening?
When a project is (re)imported from Maven IDEA configures it such way that when you invoke 'Build' from IDEA it produces the same result as Maven's 'package' goal. If you need to copy jboss-ejb3.xml to WEB-INF just put it under 'src/main/webapp/WEB-INF' directory and it will be copied by Maven and so do IDEA.
Here is an alternative to Nik's solution that I tried because I wanted to leave jboss-ejb3.xml in META-INF. Taking a look at the maven documentation, which shows how to treat jboss-ejb3.xml as a web resource and copy it into WEB-INF, I added the following to the maven-war-plugin configuration and the problem was resolved. Well, kinda sorta. But not really.
<webResources>
<resource>
<directory>../Patrac-ejb/src/main/resources/META-INF</directory>
<includes>
<include>jboss-ejb3.xml</include>
</includes>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
Although doing it this way eliminated the need to fiddle around with IDEA facet configuration settings (because Maven was configured to copy the file, not IDEA), a new problem was introduced: two copies of jboss-ejb3.xml appeared in the WAR, one in WEB-INF and the other inside the EJB JAR (in META-INF). Although there were no apparent consequences (the application ran just fine) I preferred not to have a duplicate copy of the descriptor located inside the EJB JAR.
Using the Maven EJB plugin documentation, I tried to add an exclusion to my maven-ejb-plugin configuration e.g.
<configuration>
<ejbVersion>3.1</ejbVersion>
<excludes>
<exclude>**/jboss-ejb3.xml</exclude>
</excludes>
</configuration>
This should have prevented the duplicate copy of jboss-ejb3.xml from appearing in the EJB JAR META-INF but it didn't work for me, and after fruitlessly googling various variations of "maven-ejb-plugin excludes not working properly" I gave up.
If I could have gotten the excludes to work then I would have preferred this solution over moving jboss-ejb3.xml into src/main/webapp/WEB-INF because although this solution is slightly more complex (it requires additional Maven configuration settings in two POMs), the EJB-related descriptor would remain in the EJB module.
I've decided to go with Nik's solution until I can resolve the excludes problem.

Resources