質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Struts 2

Apache Struts 2は、Apache Strutsプロジェクトにて開発されているオープンソースのJavaベースのWebアプリケーションフレームワークです。Sturts1に比べ、設定ファイルの削減、依存性の注入、POJO等の改善がなされています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Q&A

解決済

1回答

699閲覧

Struts2のコンパイル等について

kazuuumi

総合スコア4

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Struts 2

Apache Struts 2は、Apache Strutsプロジェクトにて開発されているオープンソースのJavaベースのWebアプリケーションフレームワークです。Sturts1に比べ、設定ファイルの削減、依存性の注入、POJO等の改善がなされています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

0グッド

0クリップ

投稿2023/05/16 04:17

編集2023/05/16 08:09

実現したいこと

struts2でできたプロジェクトで編集されたソースを実行時に反映させたい

前提

struts2の公式サイトから取得したFull Distributionのstruts2-rest-showcaseをEclipsにて開き、struts2-rest-showcase\src\main\webapp\WEB-INF\src\java\org\demo\rest\example配下のソースとjspファイルを少し修正を行いました。
→こちらに関しましてはJSPのテーブルにてカラムを一つ追加し、それに伴う修正を行った形です。

ほかのwebアプリ同様「サーバーで実行」を行った際にコンパイルされ自動的にclassファイルの更新がかかると思ったのですが更新されておりません。
→struts2-rest-showcase\src\main\ImportedClasses\org\demo\rest\example配下のclassファイルの更新日時に変化がないため「更新されていない」と判断しております。

実行時にはエラー等が起こらずに起動してJSPのみ反映された形で画面が表示されました。
上記ソース以外は公式のものをそのまま使用しています。
下記トップ画面
イメージ説明

試したこと

ビルドの出力先が違うのかと思い変更しようとしましたが、struts2-rest-showcase\build\classesとなっているので問題ないとおもいます。
一応classファイルがstruts2-rest-showcase\src\main\ImportedClasses\org\demo\rest\example配下にあるためそちらを指定しようとしましたがネストエラーで適用できませんでした。
また実行時にビルドするよう設定されており、クリーン、リフレッシュ等を行っております。

コード

web.xml

1<?xml version="1.0" encoding="UTF-8"?> 2<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 5 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 6 version="3.1"> 7 8 <display-name>Struts 2 Rest Example</display-name> 9 10 <!-- Filters --> 11 <!-- START SNIPPET: filter --> 12 <filter> 13 <filter-name>action2</filter-name> 14 <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> 15 </filter> 16 <!-- END SNIPPET: filter --> 17 18 <filter-mapping> 19 <filter-name>action2</filter-name> 20 <url-pattern>/*</url-pattern> 21 </filter-mapping> 22 23 <!-- Welcome file lists --> 24 <welcome-file-list> 25 <welcome-file>index.jsp</welcome-file> 26 </welcome-file-list> 27 28 <!-- Restricts access to pure JSP files - access available only via Struts action --> 29 <security-constraint> 30 <display-name>No direct JSP access</display-name> 31 <web-resource-collection> 32 <web-resource-name>No-JSP</web-resource-name> 33 <url-pattern>*.jsp</url-pattern> 34 </web-resource-collection> 35 <auth-constraint> 36 <role-name>no-users</role-name> 37 </auth-constraint> 38 </security-constraint> 39 40 <security-role> 41 <description>Don't assign users to this role</description> 42 <role-name>no-users</role-name> 43 </security-role> 44 45</web-app> 46

pom.xml

1<?xml version="1.0" encoding="UTF-8"?> 2 3<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.apache.struts</groupId> 7 <artifactId>struts2-apps</artifactId> 8 <version>6.1.2</version> 9 </parent> 10 11 <artifactId>struts2-rest-showcase</artifactId> 12 <packaging>war</packaging> 13 <version>6.1.2</version> 14 <name>Struts 2 Rest Showcase Webapp</name> 15 <description>Struts 2 Rest Showcase Example</description> 16 17 <dependencies> 18 <dependency> 19 <groupId>org.apache.struts</groupId> 20 <artifactId>struts2-rest-plugin</artifactId> 21 </dependency> 22 <dependency> 23 <groupId>org.apache.struts</groupId> 24 <artifactId>struts2-convention-plugin</artifactId> 25 </dependency> 26 <dependency> 27 <groupId>org.apache.struts</groupId> 28 <artifactId>struts2-config-browser-plugin</artifactId> 29 </dependency> 30 31 <dependency> 32 <groupId>com.fasterxml.jackson.dataformat</groupId> 33 <artifactId>jackson-dataformat-xml</artifactId> 34 </dependency> 35 36 <!-- Logging --> 37 <dependency> 38 <groupId>org.apache.logging.log4j</groupId> 39 <artifactId>log4j-api</artifactId> 40 <version>${log4j2.version}</version> 41 </dependency> 42 <dependency> 43 <groupId>org.apache.logging.log4j</groupId> 44 <artifactId>log4j-core</artifactId> 45 <version>${log4j2.version}</version> 46 </dependency> 47 48 <dependency> 49 <groupId>junit</groupId> 50 <artifactId>junit</artifactId> 51 <scope>test</scope> 52 </dependency> 53 54 <dependency> 55 <groupId>net.sourceforge.jwebunit</groupId> 56 <artifactId>jwebunit-core</artifactId> 57 <version>3.3</version> 58 <scope>test</scope> 59 </dependency> 60 61 <dependency> 62 <groupId>net.sourceforge.htmlunit</groupId> 63 <artifactId>htmlunit</artifactId> 64 <version>2.39.0</version> 65 <scope>test</scope> 66 </dependency> 67 68 <dependency> 69 <groupId>net.sourceforge.jwebunit</groupId> 70 <artifactId>jwebunit-htmlunit-plugin</artifactId> 71 <version>3.3</version> 72 <scope>test</scope> 73 <exclusions> 74 <exclusion> 75 <groupId>xom</groupId> 76 <artifactId>xom</artifactId> 77 </exclusion> 78 <!-- not necessary to compile and it force dependency convergence issues --> 79 <exclusion> 80 <groupId>net.sourceforge.htmlunit</groupId> 81 <artifactId>htmlunit</artifactId> 82 </exclusion> 83 </exclusions> 84 </dependency> 85 86 </dependencies> 87 88 <build> 89 <finalName>struts2-rest-showcase</finalName> 90 <!-- 91 <outputDirectory>src\main\ImportedClasses\org\demo\rest\example</outputDirectory> 92 --> 93 <plugins> 94 <plugin> 95 <groupId>org.eclipse.jetty</groupId> 96 <artifactId>jetty-maven-plugin</artifactId> 97 <version>9.4.46.v20220331</version> 98 <configuration> 99 <stopKey>CTRL+C</stopKey> 100 <stopPort>8999</stopPort> 101 <scanIntervalSeconds>10</scanIntervalSeconds> 102 <webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory> 103 <webAppConfig> 104 <contextPath>/struts2-rest-showcase</contextPath> 105 <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> 106 </webAppConfig> 107 </configuration> 108 </plugin> 109 <plugin> 110 <artifactId>maven-surefire-plugin</artifactId> 111 <configuration> 112 <argLine>@{argLine}</argLine> 113 <excludes> 114 <exclude>it/**</exclude> 115 <exclude>**/*$*</exclude> 116 </excludes> 117 </configuration> 118 </plugin> 119 </plugins> 120 </build> 121 <properties> 122 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 123 </properties> 124</project> 125

Order.java

1 2package org.demo.rest.example; 3 4import org.apache.commons.lang3.builder.EqualsBuilder; 5import org.apache.commons.lang3.builder.HashCodeBuilder; 6import org.apache.commons.lang3.builder.ToStringBuilder; 7 8public class Order { 9 String id; 10 String clientName; 11 String orderDetail; 12 int amount; 13 14 public Order() {} 15 16 public Order(String id, String clientName, int amount) { 17 super(); 18 this.id = id; 19 this.clientName = clientName; 20 this.orderDetail = orderDetail; 21 this.amount = amount; 22 } 23 public int getAmount() { 24 return amount; 25 } 26 public void setAmount(int amount) { 27 this.amount = amount; 28 } 29 public String getClientName() { 30 return clientName; 31 } 32 public void setClientName(String clientName) { 33 this.clientName = clientName; 34 } 35 public String getOrderDetail() { 36 return orderDetail; 37 } 38 public void setOrderDetail(String orderDetail) { 39 this.orderDetail = orderDetail; 40 } 41 public String getId() { 42 return id; 43 } 44 public void setId(String id) { 45 this.id = id; 46 } 47 48 @Override 49 public boolean equals(Object obj) { 50 if (obj == null) { 51 return false; 52 } 53 if (obj == this) { 54 return true; 55 } 56 if (obj.getClass() != getClass()) { 57 return false; 58 } 59 Order rhs = (Order) obj; 60 return new EqualsBuilder() 61 .append(this.id, rhs.id) 62 .append(this.clientName, rhs.clientName) 63 .append(this.orderDetail, rhs.orderDetail) 64 .append(this.amount, rhs.amount) 65 .isEquals(); 66 } 67 68 @Override 69 public int hashCode() { 70 return new HashCodeBuilder() 71 .append(id) 72 .append(clientName) 73 .append(orderDetail) 74 .append(amount) 75 .toHashCode(); 76 } 77 78 @Override 79 public String toString() { 80 return new ToStringBuilder(this) 81 .append("id", id) 82 .append("clientName", clientName) 83 .append("orderDetail", orderDetail) 84 .append("amount", amount) 85 .toString(); 86 } 87} 88

補足情報(FW/ツールのバージョンなど)

window11
Eclips Version: 2023-03 (4.27.0)
java java version "1.8.0_371"

素人質問になりますので不足情報等あると思います、その際はコメントをよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2023/05/16 04:53

何をどう変更して どこをどう確認して 「更新されていない」と判断されたのでしょうか。 具体的に記載願います。
kazuuumi

2023/05/16 04:57

コメントありがとうございます。 上記質問に関して 何をどう変更 →struts2-rest-showcase\src\main\webapp\WEB-INF\src\java\org\demo\rest\example配下のソースとjspファイルを少し修正を行いました。具体的にはテーブルのカラムを追加しそれに伴うような修正を行いました。 どこをどう確認して →struts2-rest-showcase\src\main\ImportedClasses\org\demo\rest\example配下のclassファイルの更新がされていないので「更新されていない」と判断いたしました。 上記で伝わりますでしょうか。。? もし不足していればコメントお願いいたします。
m.ts10806

2023/05/16 05:25

質問は編集できますので質問本文に追記を。 クラスファイルはともかく、実際の動作はどうなのかという点も確認して追記してください。
kazuuumi

2023/05/16 07:18

かしこまりました。 追記いたします。
m.ts10806

2023/05/16 07:52

jsp側は変更されてると ではJava側ということになりそうですが、それこそ挙動に影響がある修正なのかという部分が現状だと第三者が判断できかねますので、コードも提示されたほうが良いかもしれません。 期待されてるのはいわゆるホットデプロイかとは思いますが、設定周りなのかなぁと感じてはいます。 eclipseはともかくStruts2は実際に触ったことないので、手元にも環境がなくキーワードで調べて出てくる情報くらいしか持ち合わせがないのですけど…
kazuuumi

2023/05/16 08:15

いったん設定周り+修正ソース追記いたしました。お手すきの際にご確認ください。 ホットデプロイは特段期待しておらず、ソースを修正した場合、一度Tomcatの再起動から行う予定です。 struts2の情報が思ったより少なく途方に暮れてますね…
guest

回答1

0

自己解決

いくつか試して解決に至りました。
自分の思い込みでのミスでした。
今回公式サンプルのフォルダー構成が下記のようになっているのですが

C:\PLEIADES\2023-03\WORKSPACE\STRUTS2-REST-SHOWCASE │ .classpath │ .project │ ├─.settings │ .jsdtscope │ org.eclipse.core.resources.prefs │ org.eclipse.jdt.core.prefs │ org.eclipse.wst.common.component │ org.eclipse.wst.common.project.facet.core.xml │ org.eclipse.wst.jsdt.ui.superType.container │ org.eclipse.wst.jsdt.ui.superType.name │ ├─build │ └─classes │ │ log4j2.xml │ │ orders-deleteConfirm.jsp │ │ orders-edit.jsp │ │ orders-editNew.jsp │ │ orders-index.jsp │ │ orders-show.jsp │ │ struts.xml │ │ velocity.properties │ │ │ ├─META-INF │ │ DEPENDENCIES │ │ LICENSE │ │ NOTICE │ │ │ └─org │ └─demo │ └─rest │ └─example │ IndexController.class │ Order.class │ OrdersController.class │ OrdersService.class │ └─src └─main ├─ImportedClasses │ └─org │ └─demo │ └─rest │ └─example │ IndexController.class │ Order.class │ OrdersController.class │ OrdersService.class │ ├─java │ │ log4j2.xml │ │ struts.xml │ │ velocity.properties │ │ │ ├─META-INF │ │ DEPENDENCIES │ │ LICENSE │ │ NOTICE │ │ │ └─org │ └─demo │ └─rest │ └─example └─webapp ├─css │ app.css │ bootstrap-theme.css │ bootstrap-theme.css.map │ bootstrap-theme.min.css │ bootstrap.css │ bootstrap.css.map │ bootstrap.min.css │ ├─fonts │ glyphicons-halflings-regular.eot │ glyphicons-halflings-regular.svg │ glyphicons-halflings-regular.ttf │ glyphicons-halflings-regular.woff │ glyphicons-halflings-regular.woff2 │ ├─META-INF │ │ MANIFEST.MF │ │ │ └─maven │ └─org.apache.struts │ └─struts2-rest-showcase │ pom.properties │ pom.xml │ └─WEB-INF │ web.xml │ ├─content │ orders-deleteConfirm.jsp │ orders-edit.jsp │ orders-editNew.jsp │ orders-index.jsp │ orders-show.jsp │ ├─lib │ asm-9.2.jar │ asm-analysis-9.2.jar │ asm-commons-9.2.jar │ asm-tree-9.2.jar │ commons-beanutils-1.9.4.jar │ commons-collections-3.2.2.jar │ commons-fileupload-1.5.jar │ commons-io-2.9.0.jar │ commons-lang3-3.10.jar │ commons-logging-1.2.jar │ commons-text-1.10.0.jar │ freemarker-2.3.31.jar │ jackson-annotations-2.13.4.jar │ jackson-core-2.13.4.jar │ jackson-databind-2.13.4.2.jar │ jackson-dataformat-xml-2.13.4.jar │ javassist-3.29.0-GA.jar │ json-simple-3.0.2.jar │ log4j-api-2.19.0.jar │ log4j-core-2.19.0.jar │ ognl-3.3.4.jar │ slf4j-api-1.7.32.jar │ stax2-api-4.2.jar │ struts2-config-browser-plugin-6.1.2.jar │ struts2-convention-plugin-6.1.2.jar │ struts2-core-6.1.2.jar │ struts2-rest-plugin-6.1.2.jar │ struts2-velocity-plugin-6.1.2.jar │ velocity-engine-core-2.3.jar │ velocity-tools-generic-3.1.jar │ velocity-tools-view-3.1.jar │ velocity-tools-view-jsp-3.1.jar │ woodstox-core-6.3.1.jar │ xstream-1.4.19.jar │ └─src └─java │ log4j2.xml │ struts.xml │ velocity.properties │ └─org └─demo └─rest └─example IndexController.java Order.java OrdersController.java OrdersService.java

もともとあったJavaビルドパスは「struts2-rest-showcase/src/main/java」でして何もない個所を指定しておりました。新しく「struts2-rest-showcase/src/main/webapp/WEB-INF/src/java」のパスを追加して再度実行したところ更新したソースが反映されていることを確認いたしました。
いったん完了といたします。
コメントくださった方ありがとうございました。

投稿2023/05/17 02:57

kazuuumi

総合スコア4

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問