Netbeans can't find sources in non-standard maven project layout - maven

I'm trying to use Netbeans 8.1 to work on a Maven project with a non-standard project structure. In my project, my sources are under src/foo instead of src/main/java. To open my project, I click File > Open Project... in the menu. Then I navigate to my project in the file browser that opens. Then I select my project and click Open. When my project opens in the Netbeans Projects tab, it does not contain any source packages. It only shows a folder labeled Dependencies and a folder labeled Project Files.
I've tried changing the location of the source folder in the project properties to fix this. I right-click on the project, click Properties, and then click Sources in the menu on the left. Then I try to edit the Source Folder value, but the value isn't editable. It's worth noting that for ant projects, I can add sources in the project properties, but for Maven this doesn't seem possible.

Does your maven project actually build correctly? The IDE will pull the source location from your POM model. Eg.
<project>
<build>
<sourceDirectory>${project.basedir}/src/foo</sourceDirectory>
</build>

One solution is to change your project so that it uses Maven's standard directory layout. One very easy way to do that (if you have your sources under one directory), is to create symbolic link from src/main/java to src/foo:
mkdir src/main && ln -s /path/to/project/src/foo src/main/java
If you do that, Netbeans will be able to see your sources, and you can keep your non-standard directory structure.
Possible Alternative: When searching for alternative solutions to this issue, I found that I could import the project into Netbeans as either a Java Project with Existing Sources or a Java Free-Form Project (I'm not sure which one I used). However, Netbeans won't let me do that anymore, so I'm not sure if it will always work and I'm not sure of the steps I took. If you want to try that solution, click File > New Project, choose the Java category, and choose either Java Project with Existing Sources or Java Free-Form Project. In the next window, point Netbeans to your existing sources as the location of the project. As I said above, I'm sure that this worked for me once, but I cannot use this method anymore as Netbeans shows the following error:
Project folder is managed by a project foo-project-name. Instead of creating a new project just open it. If by a chance you just deleted the project foo-project-name than [sic] restart the IDE to reuse the folder.

Related

Which project files contain information that this is a maven project

There is a project on Spring. If I clone it from GitHub, then open it in IDEA, then it understands that this is a maven project, i.e. it highlights all the project folders with the right color - java, resources, etc. And if I just copy the source files of the project to another directory with all the folders, then IDEA does not perceive it as a maven project, but simply as a set of folders.
But on Github I don't see any other files except the source. And then where is all this information about the structure of the project stored?
That is, what files do I still need to copy so that the IDE recreates the entire folder structure as in the original project?
Usually, if it is a maven project, we use a pom.xml file. In case of gradle, we use build.gradle file.
Whenever a spring project is build, it reads one these files to get all dependancies.

Spring STS not recognizing project structure with Gradle

I'm trying to do this getting started guide from Spring. So I cloned the project using git from the command line. As I'm working with Gradle, I removed the Maven files from the repository to clean the project.
After that I open my STS and go to File -> Open Projects from File System and navigate to the /initial folder of the repository. The project is imported correctly but when I try to add some "java stuff" (packages, classes, etc.) I get several errors and I can only add folders and files, which is quite annoying for working.
To be more descriptive, I'll add some images so you can see what's happening. This is the project initially imported into STS as I described above:
Then I try to add some java stuff, let's say for example a source folder. So Right Click on library -> New -> Source folder and this is the result:
And in the properties of library I have the following:
So the question is: how can I tell to STS to recognize the library folder as a Java Project (or Gradle module, I don't know how to call it) instead of a plain folder so I can add my packages and classes?
Thanks in advance for your answers.
In case you would like to work with Gradle, you should use the Gradle integration for Eclipse (project Buildship) and install that into your STS environment. After that, you should be able to import the projects either from disc as existing Gradle project (not as file system) or via the wizard that integrates the spring guides into STS (Import Getting Started Content). The wizard for the guides also let you choose between the Maven and the Gradle variant, so you don't need to close and delete stuff yourself.
Hope this helps!!!

Maven archetype for JSP

I have a problem. I want to create Java Project which uses Servlets and JSP. So I create new Maven project and choose maven-archetype-webapp. So it creates the project, but there are .idea and src folder. There isn't source folder. What should I do to be generated "source" folder. I have the dependencies needed. I am using IntelliJ. While using Eclipse I have absolutely the same problem. I fix it with checking "Maven Dependencies" in "Java Build Path/Order and Export". It worked in eclipse, I don't know why. Or can someone tells me how to create project in IntelliJ which has generated pom.xml, web.xml and "source" folder. The question may be stupid, but I really don't know how and obviously I make something wrong.
Thanks for your attention.
You should try to stick to the maven default project layout convention.
All tooling defaults to this structure (see the link given above).
In Intellij you can easily create a Maven project via the "New Project" dialog.
If you want to keep your current project layout, you can try to right click on your "source/production/java" Folder and click "Mark Directory As" and then "Source root".
This marks it as Java source folder.
You should then be able to create new classes via Context menu.

Eclipse Plugin project: manage external files

I'm developing a plugin for Eclipse (4.2 on windows) that uses a bunch of external files (batch scripts, xml files, ecc).
I'm asking if there is a good method to manage those files inside the project in order to:
keep all the plugin resources inside the project for version control in SVN
possibly have an automated plugin installation (including those files outside the plugin jar)
Edit: Can an additional "Feature Project" be a solution?
Instead of having a project I would manage two: one for the plugin and one for the "feature" that references the plugin and gathers the non-plugin data.
In that case, I see that eclipse "Features" have an "installation" section (in "feature.xml"). How could I specify for each "non-plugin" file the install path location?
I'm using nested projects for this.
Create a parent project that will contain everything. For each sub-project, deactivate the default location when you create it and select the parent project's root folder instead.
Here is an example: http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/
It doesn't have a .project file in the root but having one doesn't hurt.
Just remember to import the sub-projects before you start working on them. Otherwise, you and Eclipse might get confused.

Adding maven support to existing IntelliJ module is not available

I just started an IntelliJ plugin project, and after going a few steps, I realized that I am not managing dependencies with maven. Naturally I head over to the module in the project explorer, and right click -> Add Framework Support. But Maven is not listed! In fact, the only thing listed is Groovy. What could cause this, and how do I get maven back?
The maven plugin is enabled.
Here is a brief answer how to get going with Gradle, but most questions remain unanswered.
How to manage development life cycle of IntelliJ plugins with Maven
For a comprehensive read this post : http://labs.bsb.com/2013/11/how-to-manage-development-life-cycle-of-intellij-plugins-with-maven-2/
The post also includes a link to the source code on github.
Making your plugin project use maven in IntelliJ
This is probably not what you are struggling with, but I include it just in case. Supposing you have already started a new plugin project you have two options:
Right-click on the project name in the project explorer and choose New > Module
Create a pom.xml in the project root, then right-click on it and choose Add as Maven Project
hth
First, make sure you have enabled maven plugin in
File -> Settings -> Plugins and add search the maven plugin and activate
Restart the IntelliJ.
Go and check the tool window to make it visible
go to View -> Tool Windows > Maven Projects to open it.
The above options might take some time to execute but there is a quick fix to this if you already have a pom.xml file present in the project.
Right click on the pom.xml file and you will see an option
Add as Maven Project
As far as I understood, you have to mark your folder with pom.xml as Maven module.
In order for the project to become Maven:
Go to - File -> Project Structure (or Ctrl + Shift + Alt + S)-> Modules.
In the middle, you must remove the existing module.
Then in the same place of window click on the plus -> Import module -> Select the
required folder with pom.xml -> Import module from external module -> Maven -> Next ->
Finish
You may need to restart your IntelijIdea. Better just in case to restart it.
After restarting it, it should be appear a pop-up window in the lower right corner - Import maven module -> Click on it.
After that, the folder for module and pom.xml should be displayed as Maven.
P. S. Also check before these steps, that you have Maven support for your IntelijIdea.
Solved it being root as intelliJ launcher... not the best solution but seems a workaround.
So the best solution I found yet instead of digging into filesystem to see where there is a permissions problem was to change the owner to my user
sudo chown -R myUsername:myUsergroup /opt/becauseIInstalledItHere/idea-IC-version
To get the option in the right hand of intellij you have to follow two step given below -
Right click on Pom.xml
Click on "add as Maven Project"

Resources