JavaRush /Java Blog /Random EN /tomcat - short for windows
Izhak
Level 22
Москва

tomcat - short for windows

Published in the Random EN group
I had a desire to install tomcat and make several hosts on the local computer to start with. elephantSo, first I installed the tomcat service from the website . It can be easily configured, but without detailed research it is unclear which users and with which passwords need to be entered into netbins so that it compiles and uploads the project. Therefore, I decided to spend time and use those descriptions that can easily be found on the Internet by searching for “tomcat setup” or on the tomcat page. So, if we do not follow the simple path (later it turned out that the path through installation by the installer is also correct), then the sequence will be as follows.
  1. From the website http://tomcat.apache.org we save the zip archive and unpack it into a folder with a path without spaces or any complex characters, for example, “E:\tomcat\apache-tomcat-8.0.15”.

  2. Download the latest version of the JDK from the Oracle website https://www.oracle.com and put it in a folder with a name without spaces (if you don’t do this and install it in the X:\Program Files\... folder, then when we will edit the batch file, we will have to implicitly indicate the folder name, this is not very good, the reason will be seen later.

  3. Open “e:\tomcat\apache-tomcat-8.0.15\bin\”. We see a lot of batch files and sh scripts.

    Open “catalina.bat”. There we see a lot of commented lines with environment variables that must be declared, or that may or may not be declared.

    The variables that must be declared are

    • set CATALINA_HOME="e:\tomcat\apache-tomcat-8.0.15"
    • set JAVA_HOME="e:\ProgramFiles\Java\jre1.8.0_25"

    Moreover, it is advisable to do this in a separate file called setenv.bat; to do this, simply enter these two lines in a text editor and save the file with that name in “e:\tomcat\apache-tomcat-8.0.15\bin\”

    Note: if the folder with jre installed contains spaces, then the name must consist of a maximum of the first six letters of the real name of the folder, and if such a combination is the first alphabetically on the disk, then ~1, if the second, then ~2, etc.

    For example, the name of the folder in which the jre is located is “C:\Program Files\JRE”, and in addition there is a folder “C:\places\”, then the second line in setenv.bat will be

    • set JAVA_HOME="e:\Progra~1\Java\jre1.8.0_25", or
    • set JAVA_HOME="e:\P~2\Java\jre1.8.0_25"

    Naturally, this is not very good, especially when you have two folders “Program Files” and “Program Files (x86)”. In this case, in order to name the folder with the JRE correctly, you will have to experiment ~1 or ~2.

  4. Let's try to start it, to do this, launch cmd.exe from the current directory, and run startup.bat in it. This will give us control over what is happening. If everything went well, the Java application window will launch in console mode, in which, after launch, the start time will be written, but if something went wrong, for example, the folders in setenv.bat are specified incorrectly, we will see error messages.

  5. If global variables are configured correctly and the java console window is launched, but some settings are made incorrectly, then errors can be viewed in the “e:\tomcat\apache-tomcat-8.0.15\logs\” folder.

  6. If step 4 is completed completely successfully, then in the browser window you can type 127.0.0.1:8080 and the tomcat server window will appear in the window.

  7. But if we want to enter the Host Manager settings, etc., we will be asked to enter our username and password. There is nowhere to get them, but in the conf folder there is a file tomcat-users.xml, which, if you open it, at first seems correct, but the roles and users there are commented out . And the roles and users there are clearly incorrect. So what to do?

  8. To answer the question of what roles should be and what users should be assigned in order to log into the admin panel, see page 127.0.0.1:8080. For example, you can find out about the manager roles on the page ttp://127.0.0.1:8080/docs/manager-howto.html, and instead of one admin user, as before, there are now two users: admin-gui and admin-script.

    More details about working with passwords here http://127.0.0.1:8080/docs/realm-howto.html

    So, open the file conf\tomcat-user.xml and add it there after the commented out block with logins and passwords

    <!--
      NOTE:  By default, no user is included in the "manager-gui" role required
      to operate the "/manager/html" web application.  If you wish to use this app,
      you must define such a user - the username and password are arbitrary.
    -->
    <!--
      NOTE:  The sample user and role entries below are wrapped in a comment
      and thus are ignored when reading this file. Do not forget to remove
      <!.. ..> that surrounds them.
    -->
    <!--
      <role rolename="tomcat"/>
      <role rolename="role1"/>
      <user username="tomcat" password="tomcat" roles="tomcat"/>
      <user username="both" password="tomcat" roles="tomcat,role1"/>
      <user username="role1" password="tomcat" roles="role1"/>
    -->
      <role rolename = "admin-gui"/>
      <role rolename = "admin-script"/>
      <role rolename = "manager-gui"/>
      <role rolename = "manager-script"/>
      <role rolename = "manager-jne"/>
      <user username = "superadmin" password = "pass" roles="admin-gui, admin-script, manager-gui, manager-jne, manager-script" />
    </tomcat-users>

    This way we will get the user superadmin with the password pass.

  9. About how to debug applications, etc. http://wiki.apache.org/tomcat/HowTo#How_can_I_access_members_of_a_custom_Realm_or_Principal.3F

  10. Now, using the shutdown.bat and startup.bat scripts, we restart the server and can log into the admin panel.

  11. We create virtual hosts. To do this, look here http://wiki.apache.org/tomcat/TomcatDevelopmentVirtualHosts

  12. You can also create a link to the host in the admin panel (This is the same thing we did just now).

  13. When creating new entries in hosts for win8, we first copy the file to another folder, edit it there, and then write it back. After this, restarting the computer or server is not necessary.

And finally, the free version of IntelliJ Idea does not support the web, so first you can use netbins. https://netbeans.org/kb/trails/java-ee_ru.html https://netbeans.org/kb/docs/web/ajax-quickstart_ru.html
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION