A good environment will increase the efficiency of development.
Originally I was an Eclipse user, and the classpath and Tomcat settings were all done by Eclipse, but after I met IntelliJ, which works smoothly, I could not give up that crispness and I had to switch. I did. However, for IntelliJ, you need to buy IntelliJ IDEA Ultimate (paid version) to get the "convenience" of Eclipse. It's the power of money.
I'm currently IntelliJ Community (free), for the following reasons: ・ I want to purchase books and courses, device and hardware parts, etc. for the amount of money I invest in a paid license every month. ・ I want to set some bases myself
The latter may be similar to the feeling of occasionally trying to create a package with the vim and javac commands without using the IDE.
Roughly configure Tomcat and debugger in IntelliJ Community. (1) With an app named sample-app (2) Use local MySQL for DB resources (3) Try to connect to ``` http: // localhost: 8080 / sample-app /` ``.
OS is mac.
Since it only connects Tomcat, it is related to the initial setting of java Servlet, jsp, Spring frame
0. javax.servlet
pom.xml
`web.xml (bean setting)`
(or
application-context.xml```)I'd like to omit things like that and organize the DB settings and debugging as the main.
Select and install the required version of apache tomcat from Official Home .
Occasionally, there is a problem that the latest version of tomcat and java do not match, but for example, I have java8 and java9 in a slightly old tomcat, It can be solved by lowering JAVA_HOME, which was upgraded to 9 in the environment variable settings, to 8.
File -> new -> Project...
I want to use maven, so I will use maven webapp.
I happened to cover it, but it doesn't have to be the application name.
According to Maven POM Reference
In short, groupId can be a name that includes an institution name that can be distinguished from other projects, and artifactId should be a project name.
I remember being told that I didn't have to be so particular about personal development.
Load only pom from the initial state where pom has not been read yet and is not ready to deploy. I think that JUnit is written by default, but I can not develop an application with this alone.
I have already tried it and added java-servlet and reimported it. A java-servlet has also been added to the External Libraries and can be referenced.
Convert .java files to executable .class files.
During development, we will clean it once, but since there is nothing yet, press package to generate a viable target package. I think the name was the default name.
It's done. Similar to the File-> Project Structure-> complier output setting.
The light bulb mark says that the Ultimate version is good lol ..
It's exactly the same story, but press + on the upper left to add Maven, and pass a command that can do clean and package at the same time as an argument command in advance.
It's a Working directory, but it had to be the absolute path of the application's directory. In my case, I put it in my mac's home directory, so I wrote it that way. Also, the name sample-config is appropriate.
-Dmaven.test.skip = true is an option to omit the test when you want to shorten the deployment time. It seems that omitting the test is not recommended originally, but the deployment work itself becomes heavy due to the increase in files, so I use it a lot.
And this has been added. It's easy to proceed with just one click.
Get the mvn command from the official home, install it,
$ cd {$APP_HOME}
$ mvn clean package -Dmaven.test.skip=true
It is also convenient to hit.
{$catalina_home}/conf/catalina/${host_name}/
Create a $ {APP_NAME} .xml
file directly under it.
{$CATALINA_HOME}Is your own apache-At the location of tomcat${HOST_NAME}Is localhost if it's local.
#### **`${APP_NAME}.Although it is xml, sample is used for the application created this time.-I named it app, so if you express it with an absolute path,`**
```Although it is xml, sample is used for the application created this time.-I named it app, so if you express it with an absolute path,
#### **`/My tomcat/conf/Catalina/localhost/sample-app.Will be xml.`**
{$CATALINA_HOME}/conf/Server directly below.There is xml, and it works even if I write it directly,
This is a setting common to all applications, so if you want to specify settings for each application such as DB connection, do not touch Server.xml directly under conf and `` `{$ CATALINA_HOME} / conf / Catalina / $ {HOST_NAME } / `` `I think it is better to create a configuration file for each co-context (application) directly under`.
For example, write the DB Connection (MySQL) settings in Resource and save them.
#### **`sample-app.xml`**
```xml
<Context docBase="{$APP_HOME}/target/sample-app" path="/sample-app" reloadable="true">
<Resource
name="jdbc/${jdbc_NAME}"
type="javax.sql.DataSource"
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://${DB_SERVER}/${DB_NAME}?userUnicode=true&charactorEncoding=UTF-8&autoReconnect=true"
username="${USER}" password="${PASS}"
validationQuery="select CURRENT_TIMESTAMP"
/>
</Context>
{$APP_HOME}Is the absolute path of the directory where the app is being developed.
It is ``` {$ APP_HOME} / target / sample-app}` `` directly under, but it is the place where the class file is ejected every time you deploy, which is set in IntelliJ.
I set it to ``` / target / $ {APP_NAME}` ``. If I can specify the location where the class file will be saved, I'd like to name it.
The standard is a relative path from / webapp, but this time I specified it as an absolute path.
* <b> path </ b> <br> Context path. The default is the value of the docBase attribute, so it should be optional if you want to sample-app like the value of the docBase attribute like this time ...
* <b> reloadable </ b> <br> If there are updates to .class or .jar files, this is a flag that determines if Tomcat will check if they are reloaded automatically. Set to true during development. However, I think it is better for performance to rewrite it to false when all development is finished.
## Resource --Set up DB connection
Add `` `<Resource> ... </ Resource>` `` for the number of databases you use.
* <b> driverClassName </ b> <br> Fully qualified class name for the JDBC driver.
* <b> type </ b> <br> Resource type. When using a data source, specify `` `javax.sql.DataSource```.
* <b> auth </ b> <br> Resource control method. When using a data source, specify `` `Container```.
* <b> name </ b> <br> This is the name given to the data source.
> * Example of jndi (Java Naming and Directory Interface) and Servlet configuration in Spring Framework <br>
It's like giving an object a name (binding). <br>
#### **`web.Of xml<servlet-mapping>Specified in<servlet-name>If is a sampleApp, I think I would write a configuration file with a name like this. application-context.It may be set using xml.`**
If you put
name =" jdbc / sampleDB "
inResource
earlier, you will get `` `java: comp / env / jdbc / sampleDB```.
This does not cover all attributes ... for example Assuming personal use of local resources instead of external DB, connection pool idle settings maxIdle </ b> and I've omitted maxActive </ b> for the maximum number of connections in the pool.
- Connection pool The pool here has the meaning of holding. A connection pool can hold multiple connections between the application and the DB server. It is a function to reuse the connection and manage the connection status of the database. Close (release) is a process to return the used connection to the pool for the next connection.
- idle This is a pooled (reserved) connection.
$ cd ${apache-location of tomcat}/bin
$ sh startup.sh
At the end
$ sh shutdown.sh
Occasionally, it accidentally double-starts, and the process remains, so in that case
$ ps -ef | grep tomcat
Then give the appropriate number `` `kill```.
What you see is the jsp provided by default here. This is the target.
If you try deleting target / sample-app / index.jsp, you'll see that the page is missing 404. You can do it again by deploying it again.
bin/setenv.sh Directly under the bin directory directly under the directory of apache-tomcat earlier Create setenv.sh.
$ cd ${apache-location of tomcat}/bin
$ vi setenv.sh
The contents are as stated below.
export JPDA_ADDRESS=9999
export JPDA_TRANSPORT=dt_socket
9999 doesn't make sense, because it's a port number that doesn't seem to be assigned ... It's like deploying and running on port 8080 and remote debugging on port 9999.
Run -> Edit Configurations...
$ cd ${apache-location of tomcat}/bin
$ sh catalina.sh jpda start
It's a startup with options, so you don't have to do `` `$ sh startup.sh```.
If you put a breakpoint as usual and pop the bug, it's okay.
Since the initial settings are not done on a daily basis, I sometimes had a hard time in case of emergency, so I wrote it as a memo.
I think the best way to build an environment is to suit you. For that purpose, it may be the first to try various things including the paid version.
that's all
All sample names have been unified to sample
for easy understanding.
Recommended Posts