tomcatでwebsocketしたい

なんか結構悩んで時間かかったからメモ

WebServerを新しく構築しようと思ってんで、高速に通信出来るようにしたいからwebSocketを使って通信しようかなーって思った

https://www.pegaxchange.com/tag/setup-tomcat-9-server-in-eclipse-neon/

まぁここ見ながらやったら開発環境は基本的にできた

開発環境:Eclipse IDE for Java EE Developers
https://www.eclipse.org/downloads/packages/release/neon/3

なんかJava SEで動いたからこれいれる
Java SE Runtime Environment 8 Downloads
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
jre-8u181-windows-x64.exe

ハマったポイントがeclipseのneonだとHelpのEclipse MarketPlaceで~みたいな記事あったけど、できなかった。

https://tomcat.apache.org/download-90.cgi

から9.0.0.M20の64-bit Windows zipをダウンロードしてください

そしたらコピペだけど

例えばCドライブ上に解凍した後

In the Preferences dialog, select Server > Runtime Environments and then click on the Add… button to setup a new runtime environment.
Eclipse IDE for Java EE Developers – Preferences > Server Runtime Environments > Add

In the New Server Runtime Environment dialog, select Apache Tomcat v9.0 from the list and then click on the Next button.
Eclipse IDE for Java EE Developers – Preferences > Server Runtime Environments > New Server Runtime Environment

ここでtomcat installation directoryで解凍したファルダのC:\Tomcat 9.0 指定
JREはデフォルトでいいとおもう

Specify the installation directory of Tomcat by clicking on Browse and selecting the root folder of the Tomcat installation. In this example c:\tomcat9 was used as the root folder.
Click on Finish to continue.
Eclipse IDE for Java EE Developers – Preferences > Server Runtime Environments > New Tomcat Server Runtime Environment

The Apache Tomcat v9.0 web server is now available as a server runtime environment in Eclipse and can now be used to deploy and run Java web modules containing Servlets, JSP files, web services and so on. Click on OK to close the Preferences dialog.
Eclipse IDE for Java EE Developers – Preferences > Server Runtime Environments > Apache Tomcat v9.0

してください

記事消えたら嫌だからついでに後もコピペ

5 Setup of new Dynamic Web Project in Eclipse

A Dynamic Web Project in Eclipse is a project facet for developing Java web applications as defined in the Servlet Specification. It generates a web application deployment descriptor (web.xml) and allows to export the project to a web archive (WAR) file for deployment to a Servlet container such as Tomcat.

On the Eclipse Welcome page, select Create a new Java EE Web Project or use the Eclipse main menu and select File > New> Dynamic Web Project. Both links will show the same dialog for configuring a new dynamic web project.
Eclipse IDE for Java EE Developers > Create a new Java EE Web Project

In the Dynamic Web Project dialog, enter the project’s name and select the target runtime, in this case Apache Tomcat v9.0.
Select the Dynamic web module version, in this case it is 3.1, indicating Servlet Specification 3.1, then click on the Finish button.
Eclipse IDE for Java EE Developers > Create a Dynamic Web Project

The new dynamic web project will now show up in the Project Explorer of Eclipse. To open the Project Explorer, navigate to Window> Show View > Project Explorer in the Eclipse main menu.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project

It may be necessary to configure the project’s build path so that the Tomcat 9 JAR files are added as a dependent library to the project. These JAR file include the Servlet API, Annotations API and others.
Create a new user library by navigating to Window > Preferences in the Eclipse main menu.
In the tree menu of the Preferences dialog, navigate to Java> Build Path> User Libraries.
Click on the New button to add a new user library.
Eclipse IDE for Java EE Developers > Preferences > Java > Build Path > User Libraries

In the New User Library dialog, enter a library name, here it is Tomcat9Library
Eclipse IDE for Java EE Developers > Preferences > Java > Build Path > User Libraries > New User Library

The new library now shows up in the User Library list. Click on Add External JARs to add the Tomcat JAR files to it.
Eclipse IDE for Java EE Developers > Preferences > Java > Build Path > User Libraries > Add External JARs

In the JAR Selection dialog, navigate to the Tomcat 9 “lib” folder. In this example, the complete folder path is c:\tomcat9\lib.
Select all of the JAR files in that folder and click on “Open“.
Apache Tomcat 9 lib folder JAR files

The JAR files are now listed under the newly created library.
Click on OK to close the Preferences window.
Eclipse IDE for Java EE Developers > Preferences > Java > Build Path > User Libraries > Tomcat 9 JAR files

Adding the library to the web project: In the Eclipse Project Explorer, right click on the project name and select Properties from the context menu.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project > Properties

In the tree menu, select Java Build Path and open the Libraries tab in the main area.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project > Properties > Java Build Path > Libraries

Click on the button Add Library and select User Library in the Add Library dialog.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project > Properties > Java Build Path > Libraries > Add Library > User Library

Select the newly created user library, in this case, Tomcat9Runtime and click on Finish.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project > Properties > Java Build Path > Libraries > Add Library > Select User Library to add to the classpath

The library is now added to the web project’s list of dependent libraries.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project > Properties > Java Build Path > User Library

When expanding the Java Resources > Libraries node in the Project Explorer tree menu, the JAR files from that library are now listed.
Eclipse IDE for Java EE Developers > Project Explorer > Dynamic Web Project > Java Resources > Libraries > User Library

ながいなー

まぁとりあえずユーザーライブラリーに登録して、それを毎回使うようにしましょうーってことぽい

あと新規のServlet(.javaのファイル)を作るときNew> Servletってするんだけどいつも忘れる

んで、eclipseの左上あたりに強制的に動作を停止させるボタン表示させるなら↓いる。

https://sourceforge.net/projects/tomcatplugin/files/
1. Eclipseのtomcatプラグインをダウンロード
2. Eclipse>help>Install New Software
3. Work withのadd>Archive>手順1でダウンロードしたzipを選択
4. Tomcat Pluginが表示されたらチェックしてインストール
5. Eclipse > 環境設定
6. Tomcat
7. Tomcatバージョンを選択
8. Tomcat Homeを選択(C:\Tomcat 9.0)
9. コンテキスト宣言モードを設定

あとテストサーバーとかで試すときfiddlerとかで解析させるのが便利だけど、httpsのオレオレ証明書で怒られる場合はfiddlerのoptionのcaputure https チェックしてdecrypted https trafficにチェックして、右らへんにactionってあるからそこからtrust root certificateで証明書作って、Windowsに登録したらexport root certificate to desktopして、それをfirefoxの「編集」->「設定」->「プライバシー」 & 「セキュリティー」->「証明書」->「証明書管理」とかで認証局証明書としていれる

[Fiddler] The Fiddler AutoResponder is enabled, but this request did not match any of the listed rules. Because the “Unmatched requests passthrough” option on the AutoResponder tab is not enabled, this HTTP/404 response has been generated.
の場合はAutoresponderのパススルーを有効にしてください

んでwebsocketでfirefox console securityerror the operation is insecure って言われる場合は(ws://だと言われる)about:config で network.websocket.allowInsecureFromHTTPSを有効

とりあえず開発がんばろ

↓弊社で開発、販売しているソフトウェアです↓

MediMonitor無料ダウンロード  

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です