Maven archetype for JSP - maven

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.

Related

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!!!

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

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.

How to copy files with IntelliJ

I'm using IntelliJ 14.1.1 on Windows.
I have a project (mainly java) with a little web module, built with maven.
In my web module, I'd like to accomplish this scenario :
I edit a Javascript file located in the web module, folder resources/js
When IntelliJ automatically saves the file, I'd like it to be copied automatically to target/classes so that my web server detects the change and reload it automatically.
My goal is to have immedlate feedback : I edit a JS file, and then I have it available in my browser.
The only way I found is to go to "Maven Project", and assign a shortcut to the maven goal which compiles the module. But this takes too long, and it's far from the "Ctrl+S" of Eclipse (Eclipse auto build let me have this behavior).
I also tried to use the File Watcher option of IntelliJ, but it seems it can only parse less/css and I cannot make a simple copy of file/folder with it.
Any help would be welcome to achieve such an immediate feedback on typing in IntelliJ.
Thank you

Maven Tags doubts

Hi all as i am new to maven project so can any body clear me about the tags as what i am thinking is that " " is name of the package where you want to keep your source codes and is the tag where we are mentioning project name for example without using maven we are creating a project through eclipse so we foolow the following steps
1-> new project
2->project name (in case of maven this comes under tag)
3->we create a package name for keeping source codes inside it (in case of maven this comes under tag )
so like this we proceed in our developmennt.
please sujjest me whether my understanding is correct as i have described above.
waiting for your reply
I think you want to know some basic things about MAVEN project.
Like how to Create a maven project.
How is its directory Structure,etc.
Let me help you with it.
New Maven Project
Give some name,select type of packaging from dropdown(jar/war/pom)
Once project created add to your POM file.
Write web.xml(dispatcher servlet)(src->main->webapp->WEB-INF)
Write you Code in some package.
You need Maven installed on your eclipse and also you must set user settings.
INSTALLING MAVEN
Click Install new software option on your eclipse. You can find it under HELP tab.
search "maven for eclipse kepler" and install that particular setup.
Now once done open "preferences" Under Maven->Installation browse to the Apache-maven path wherever you have saved it.
Now change User setting,give path of your settings.xml(this xml has path of your repository)
Now you are done with installaion.
I hope this is answer to your queation as your question is already very confusing.

Why servlets can be created only under the resources folder?

I'm trying to develop a new java web application from scratch. I'm using the IntelliJ IDE, and maven build tool.
Why servlets can be created only under the resources folder ?
Why jsp filels can be created only under the webapp folder?
Thanks
Sounds like you need to do some research into how Maven is building your project.
You should create servlets under src/main/java folder.
Run the maven build and then explore the generated WAR file, this way you can get an idea of how Maven is structuring the project.
You should see the that the webapp folder is in fact simply deployed at the root of the WAR file, hence your JSPs are placed in the correct location.
Thanks everybody, but i resolved the issue myself.
The Solution:
Go to the folder which you want to make available for java classes or servlets, and right click it.
Choose: Mark directory as...
Choose: Sources Root

Resources