Intellij idea 13 was initially introduced, and it seems that both visual and operational aspects are good, but it is not easy to get started with netbeans, especially Tomcat is quite different in use. The engineering structure is also different. From the Internet, intellij idea projects are equivalent to netbeans workspace netbeansprojects or workspace, while module is equivalent to a project in netbeans. Besides, Jar packages are generated differently. intellij IDEA requires special settings. Otherwise, the class file tree is generated.
Start the combination step by step:
First, we need to start Tomcat from intellij idea and access the webpage. This is the first condition:
1. Create a Java project testweb, or skip this step. Select the project SDK.
2. Create a module (jspweb) under the project, and select [javaee web module] under [Java Enterprise] on the left of the pop-up window, if no option exists in the [Application Server] column, select [New...] on the right. -- [Tomcat server]: Configure tomcat. Select it after configuration.
3. Configure the release of the web project below. Press (F4) or right-click the project name to bring up [Open Module Settings] (Note the + number above) the following options (artifacts-web application: exploded-from modules ...). In the pop-up dialog box, you should have a web project jspweb, select it, and click OK. Last
4. Do not forget to close the settings window after completing the above operations. Configure Tomcat below. Click the Tomcat name you set in the upper-right corner of the page and select Edit configurations.
Select the second tab (deployment) on the displayed page)
Click the plus sign on the right and select the first (artifact ...)
In the pop-up window, you should have the web publishing project you just added in the Module Settings. Note that the application context on the right needs to set a relative directory (equivalent to a virtual directory) for access ).
5. Now you can click application servers in the IDE and click the triangle button on the left to start Tomcat. If it is normal, a style will appear, the jspweb access page is displayed. add a few words in JSP to view the test result. The test result does not have any content)
========================================================== ======================
The above is the most basic Tomcat release process.
========================================================== ======================
The following is a simple test of the web project:
1. Modify the Web. xml in the WEB-INF in jspweb and add a listener parameter: COM. testjsp. testlistener
2. Create a class com. testjsp. testlistener in SRC in jspweb and implement the interface servletcontextlistener. The Code prompts an error because no dependency package is imported. In fact, there is still a problem about setting the project dependency package. However, when creating a web project, the servlet-API is automatically imported, so no additional settings are required, you only need to place the cursor in the wrong place servletcontextlistener and press the [Alt + enter] combination. The Code will be automatically imported into the package. If an option is displayed, select improt class...
After the package is imported, the Code prompts you that there are still errors. If you have not implemented the relevant interface methods, press [Alt + enter] to combine them, select (implement methods), select the two listed methods, and click OK, the code is automatically inserted. We need to modify the code and add the output statement to see the prompt.
Now, restart Tomcat through the application servers panel below ide. If it is correct, the result will be displayed.
========================================================== ======================================
The following is the import settings for web projects that depend on other packages, including packages generated by other projects and existing packages:
1. Create a New Java module in the testweb project, and select the Java module under Java and name it cm-listener. After the module is created, press the shortcut key F4 to bring up the module setting interface and select (artifacts-jar-from modules with dependencies ...)
2. Select the jar package cm-listener to be generated. Save the jar package by default.
3. To test this project, create a listener class named net. Test. hellolistener in SRC of module item cm-listener to implement the interface servletcontextlistener. At this time, the code will return an error message automatically. After [Alt + enter], the relevant package will not be automatically imported, but a prompt will appear (in fact, selecting the first item can solve the problem, but in order to understand how the dependency package is added, we do not select it here.) This is because cm-listener is a Java module, not a web module, servlet-API. jar is not automatically added to the dependency path:
4. Select cm-listener module in the project, press F4 to bring up the module setting interface, select modules in Project Settings, and select cm-listener in the list displayed on the right, select the dependencies of the module. You can see that there is no Tomcat Library (servlet-API. jar is included in this library), and now add it manually. Click the plus sign on the right. In the pop-up menu, select the second library...
Select Tomcat under application server libraries and click Add selected.
The confirmation is complete. Return to the source code editing window, and [Alt + enter], you can import the relevant packages normally. Modify net. Test. hellolistener source code
You can try to manually generate the cm-listener.jar. Choose build-Build artifacts from the menu. In the displayed window, select cm-listener build.
5. For testing, modify web. XML
At this time, if you start Tomcat, you will be prompted to start the listener error, because the listener class net. Test. hellolistener is in another jar, and the Web project does not have this package.
6. Add a dependency package to a web project. Note that if you do not need this package during web project compilation, you can skip this step. The steps are similar to Step 1 above, except that the jspweb module is now set, and after point +, the dependency of the 4th modules is selected..., And the created jar Project CM-listener is selected.
IDE will have a prompt.
7, now add cm-listener to the release directory, such as select, note in the output layout settings under the WEB-INF to create a directory lib
Select Lib, right-click the artifact under add copy,
In this case, a selection window appears, listing all created jar projects in the project, and selecting cm-listener
The structure is as follows:
Restart Tomcat and you will see what you want!
========================================================== ======================================
The above is a reference between projects within the project.
The following is a simple test to reference other existing packages using the CM-listener project:
1. Modify the source file in the above cm-listener project and add log operations for org. Apache. commons. Logging. This class is located in the commons-logging-1.1.3.jar, please download from the Apache website:
After modification, the editor will prompt an error and the package cannot be found.
2. A package may be used by multiple modules, So we add the commons-logging-1.1.3.jar to the Lib library of the testweb project and open the Module Settings:
Go to the location where the commons-logging-1.1.3.jar is located. After you confirm, a window pops up asking you to select the project you want to use the package for. Here you can select cancle not to specify:
Note: after adding the settings, click OK on the Module Settings page to save the settings. Then, F4 enters the Module Settings again, so that the Set lib library can be seen elsewhere.
3. After Entering Module Settings, select the CM-listener Project Settings, select the dependencies of the module, click the plus sign on the right, and select the second library in the pop-up menu... (this step is similar to step 4th of the CM-listener created above), you can see that there is an additional project libraries project, select the commons-logging-1.1.3.jar, Add.
4. Keep OK to save the settings and return to the source file editor. After [Alt + enter], you can import the relevant packages normally. Now you can recompile and build the package. So far, you can build a cm-listener.jar normally, but if you start Tomcat, you will find that the error is still guaranteed. Because the cm-listener.jar depends on the commons-logging-1.1.3.jar, while the jspweb project is in the previous settings, the cm-listener.jar is only deployed at the time of release, and the commons-logging-1.1.3.jar is not deployed.
5. Enter Module Settings, select jspweb in artifact (see the settings when cm-listener is created above), select the Lib folder under the WEB-INF (created earlier ), select library files under add copy of and select commons-logging-1.1.3.jar. Save settings.
Restart Tomcat and you can see that it is running normally!
========================================================== ================================
The above may be a bit messy, or a simple summary.
========================================================== ================================
Simple Steps for creating a web project:
1. Create a new project. Select the SDK as your JDK.
2. Create a project module. For a web project, select [javaee web module] under [Java Enterprise].
When creating a web project, be sure to select the Tomcat server. If there is no new one (this is simple ).
3. Select the web project created in the project window, press (F4) or right-click to bring up [Open Module Settings], and select artifacts-web application: exploded-from modules ..., in this window, only web projects will appear. This step is the Web Publishing settings. You can change the publishing path by yourself. To simplify the process, save the default settings here.
4. Configure Tomcat and select the first (artifact...) at the Point + in deployment. If you do not do step 4, artifact... will not appear. After adding the project, do not forget to set application context. For example, if I set it to (/Hello), the Access address of this web project is localhost: 8080/hello.
5. Modify index. jsp in the web Project and enter a few test words.
6. start Tomcat through application servers of intellij idea (in the lower-left corner of the Interface) to view the effect.
========================================================== ==================================
Add a reference to the package:
1. Create a project (module) and a Java module in the project (note the difference between the project and the web project)
2. Because you want to package and release all modules, select artifacts-jar-from modules with dependencies ..., select the project to be packaged and released (note the difference between the project release settings and the web project release settings ).
3. Build the jar package through Build-Build artifacts in the menu bar.
4. Open Module Settings. You need to set two parameters here.
List all projects under modules, select the project to be set, and add the required package in the dependencies on the right through the + sign.
Artifacts lists the projects that have been set for release. For example, the jar package deployed in the Lib of the web Project is set here, but you need to set the Lib folder by yourself.
5. If another project is required during project compilation, select module dependency when setting dependencies for the project, and select the corresponding project; if you need another existing package instead of a project, select the first jar or directory to locate a jar on the disk. Select the second jar to find the jar from the IB database. If you select the second library, you need to add the jar in libraries in the Project Settings. After adding the jar, you need to save the Project Settings and re-enter the project settings, to view the packages under project libraries.
6. When a web project is released, release the required jar package to Lib. You need to set it under artifacts set in the project and select the published web project, create a directory lib under the WEB-INF in output layout, right-click the Lib folder, select Add copy of-artifact (other project packages in this project ), select Add copy of-library files (packages can be added to the project libraries set in step 1)
If any error occurs, please correct it!