Where can i find to create new servlet file with intellij? - java

I'm new learner of JSP programming, so I choose intellij as my IDE.
I installed Intellij Ultimate, JDK14 from oracle,and Tomcat 9, and then searched for creating new project.
But, most of the posts which explain how to create a new servlet project says that
"when you create new project, you can find Web service checkbox under Additional Libraries and Frameworks in Java Pane."
Even JetBrains' are saying the same thing, (https://www.jetbrains.com/help/idea/preparing-to-develop-a-web-service.html), but I couldn't find it.
Of course I checked whether my plugins are enabled.
Anyway, I found another way to create it by selecting Java Enterprise, and after clicking Next, checking "Web profile" from Libraries and Frameworks.
But now, Another problem occurs because I cannot find "new - servlet project with right clicking on the src or src/main/java
Why are these things happening? Even if I find some way to create servlet file, maybe there will be other problems like this, I think.
Is there any prerequiste for JSP project? or is it just because intellij has been ungraded? I wanna know the reason why my intellij is different with others.

I found this way I hope it works for you as it did for me. First I would recommend you to add support for Maven framework or you just could download the JAR file of the needed dependency for creating and managing servlets Java Servlet API.
Adding Framework support for Maven
On the Project tool window, you have to select the module you want to add Maven Framework support to, right-click it and select Add Framework support. Just like this:
Adding Maven support
On the new window you just select Web Application and Maven from the list of available Frameworks. When selecting Web Application it creates a web package and its web.xml configuration file. When asked, accept creating the web.xml file to proceed. After these steps your project structure might look like this:
Project structure after adding Maven and Web application frameworks
Adding Java Servlet API dependency to pom.xml
Now you need to open the pom.xml file. This file helps you to add and manage your project dependencies as it allows you to retrieve them from the Apache Maven repository instead of downloading the JAR files and adding them manually to your project. You need to add the next dependency:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
Your pom file should look like this after the previous step:
Adding Java Servlet API dependency
As final step, we need to open the Project Structure settings by pressing Ctrl + Alt + Shift + S or by navigating through File > Project Structure. Here we are going to find a Project Settings section on the left side of the window. We need to go to Facets and you may find a facet named Web. On the bottom of the window you should see an option called Source Roots. You have to enable it by clicking the checkbox, then click Apply and finally OK. You have to make sure that path shown in this section is indeed the path to your projects' src > main > java folder.
Marking folder as source root
Once you've done that, you should be able to go to any package in your project and create a servlet as follows: New > Servlet.
Creating servlet
Note: if you got a syntax error when pom.xml file was created the only thing you need to do is to change the <groupId></groupId> tag content to a fully qualified name you want your project to be identified by.
Given your project a qualified name
Note: I wasn't able to find a way to configure permanently the src > main > java folder as source root, so every time you close and reopen your project you need to go to Project Structure (Ctrl + Alt + Shift + S) > Facets > Web and mark it as source root again. If you find a way to do this permanently I would appreciate you to share your method.
More info on
Create a Maven Project with IntelliJ IDEA
Getting started with Web Service

right click src\java > Mark directory as > source root
go to File > Project Structure...
select Facets
click Web(project name)
check src\main\java under source root.

First, you can go to src > main > java, then right click:
and then New > Create New Servlet.

Related

Adding External jar copy to Project

I created a project but I am using an external library for it. enter link description here
I added the library to my Beans as follows:
Right click on folder "Libraries"
Add Library
Create...
Gave it a name "gson 2.7"
Picked the class, source and javadoc files.
I went on and continued programming and then I added my code to Github. Then when I cloned it my Library was missing.
How can I fix this ? How can I make it dynamic so I dont have to worry about this anymore. In other words I need to add the library to my code and not just the reference.
Thanks a lot for the help
Just upload a copy of your library to github.
I have not used netbeans, but from what I understand it adds the jar somewhere outside of your project directory, and it simply adds the location of the jar to your classpath. When you upload and then clone the project from github, the jars are not uploaded/cloned, and the project structure metadata for your project is also lost from netbeans.
My suggestion is to learn and start using a build tool like maven. It takes up the responsibility of adding your dependency libraries everytime, given that you have an internet connection. It also adds the libs to the target directory of your project folder, so you probably will need the internet connection only once. The libs will be uploaded and cloned back from the github repo everytime.
IDEs like eclipse have inbuilt support for maven, so you don't even have to worry about executing the mvn commands. Here's a tutorial that will get you intrigued - with the IDE that you prefer.
https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
Thanks a lot for all the replies and comments.
Technically there are two approaches to my problem. For this articular example I chose to copy the external jar files to my project.
1. Copy jar files to your project.
Go to project properties
Under Libraries folder make sure to set up a libraries folder by following the steps.
Add Library at the bottom ( you can create or import; since I already had gson in Netbeans I just imported it.)
Press ok to confirm and you are done!
2. Use Maven
Go to plugings and make sure you have all Maven plugins installed, if not do so.
Create an new project and choose maven/java application
Follow the prompts
At this point you can start coding (in my case I just imported my class files from the other project)
Right click in "Dependencies folder and then "Add Dependency"
Under query type the repository you are looking for; in my case "com.google.code.gson : gson : 2.7"
Click add and you are done!
Thanks a lot to everyone for the help :)

Eclipse Web Project Name

I have 2 web projects and 2 framework projects in my Eclipse workspace. I copied one project to another and changed names in the .project file. All code and JSP pages compile fine. When I go to the Add/Remove dialog of my Tomcat eclipse server the new web project shows up named properlyy but in parenthesis it has the original project name. This is true of the new framework project also. Does anyone know where I need to change the name.
Found it.
.settings\org.eclipse.wst.common.component

Eclipse Plug-in development. Can i use an already existing jar file with my plug in?

Im writing a server based application and i would like eclipse to be able to interact with it.
I was wondering if eclipse PDE can handle using an external jar to interact with RabbitMQ. Also would i have access to the editor i.e. could the server respond and then update the code on the users end inside the editor pane?
Also if anyone knows any good resources for eclipse plug-in development that would be great as the only books i can find on amazon are a few years old
Thanks,
Ben
You can include any JAR in your plugin and write code that uses it.
Copy the JAR into your plugin project (usually they're placed into a lib folder in the project).
Open your plugin's manifest or plugin.xml file and go to the Runtime tab.
In the Classpath section, use the Add... button to add the JAR.
Go to the Build tab and make sure the JAR is selected at least for the Binary Build.
Save.
Now you should be able to write code that uses the JAR and when you build your plugin it will be packaged in your plugin.
If you find that you'll be writing multiple plugins that go together and all use the same JAR(s), there's a better way to package it, but I'll leave those details out for now.

The question on configuring build path which involves a lot of libraries

For a newly created project B, I need to build the path the exactly same way as an existing project A. After opening the “java build path” window by clicking “build path--> configure path”, I found that There are a lot of libraries involved in Project A. How to handle this kind of scenario? Add those jar files one-by-one?
If you can locate all those jars on your file system/network, the best thing for you to do is to create an eclipse User Library.
Creating a Library
Window >> Preferences >> Java >> Build Path >> User Libraries
Select New
Give your library a name
Ok
Select Add Jars
Add all the jars you need for your library
With this library created, you can share the same jars between projects easily by importing the library as opposed to each individual jar file.
Importing a Library
For each project that needs a particular library all you have to do is import the library.
Open the project's properties
Select Java Build Path
Select Libraries tab
Select Add library
Select user Library
Select your Library you created
Finish
Note
User Libraries do not belong to projects, they belong to the User but can be referenced by multiple projects.
Using libraries allows you to update your jars only once for all projects that share the same jars.
I hope that helps :D
If you are using Eclipse and you want your new project to have the exact same libraries/dependencies as a previous project, you can copy the appropriate contents of the .classpath file from the old project to the new one.
This would include any classpath elements with a kind="lib" attribute. You may have to update the path attribute if the location is relative.
This assumes you aren't using something like Maven for dependency management...
There are 2 options:
Create a User Library.
Window > Preferences > Java > Build Path > User Libraries
The good thing about this is, you can re-use it provided you need exact set of libraries for other projects.
Bad thing is, if you want to add new JARs to this, you have to modify it. And modifications is .....not difficult, but takes time. Also, if you need slightly different set of JArs for different projects, then either you have to add some not-needed JARs in either/both projects or you have to add this User Library + some external JARs.
EDIT 1
Go into the Eclipse preferences > Java > User Libraries. Click on "New.."
Choose a name for your user library. Leave the "System Library" checkbox unchecked. Push "OK".
Select your library and click "Add JARs...". Navigate to the location where you put the library.
For each JAR file, there are 4 additional parameters you can attach to the JAR: Source location, Javadoc location, Native library location, and access rules. Except the rest 3, Native library location is not an optional field, and must be included if the JAR requires one
OR
Simply add as External JARs.
Good thing: Simple, straightforward.
Bad thing: If you need too many jars, you have to keep track of each separately.

sHow do I add external JAR files in a Web Free Form Application in NetBeans?

I have a Red5 application that i want to work on using NetBeans 6.8.
I know I can use a web Free-Form Application, the only problem that I'm having is to add external jar files.
When I go to the project's properties, Where exactly do I add the external jars that I need in order to properly compile the application?
update
i think that the following URL addresses my problem but i can't really understand the solution.
http://www.bradmcevoy.com/blogs/netbeans_ant_ivy.html
You can add the external libraries to your project's Libraries folder, or you can add them in the NetBeans' Tools > Libraries dialog. The latter can be shared among several projects. This answer includes illustrations.
Addendum: For free-form type projects, the Projects > Properties mentions, "Any settings modified on this panel are for IDE purpose only and do not change the build script. If you want to make changes in build process, please modify your build script manually."
found a solution here but it's probably for a lower version of netbeans:
http://forums.netbeans.org/viewtopic.php?p=5329
i get an error on the tag.
Since it is a free-form project, you have to make sure that your build script puts the correct jars into the compile-time classpath. You also want to make your Netbeans project libraries match for auto-complete purposes and error highlighting and such (ie when you view Project Properties->Java Sources ClassPath).
Ok I finally resolved the issue by re-creating the project using the step by step tutorial in the following URL : http://blogs.oracle.com/coreqa/entry/setting_up_freeform_project_correctly

Categories

Resources