From d1742ab7f9dcf157d9c810a042b1738dc43a8f85 Mon Sep 17 00:00:00 2001 From: "iwauo.tajima" Date: Thu, 6 Jun 2024 05:53:36 +0900 Subject: [PATCH 1/2] original struts1-blank project --- .gitignore | 1 + .tool-versions | 2 + Dockerfile | 3 + pom.xml | 53 ++++++ scripts/deploy-local.sh | 34 ++++ .../resources/MessageResources.properties | 44 +++++ src/main/webapp/WEB-INF/struts-config.xml | 179 ++++++++++++++++++ src/main/webapp/WEB-INF/validation.xml | 90 +++++++++ src/main/webapp/WEB-INF/web.xml | 50 +++++ src/main/webapp/index.jsp | 25 +++ src/main/webapp/pages/Welcome.jsp | 39 ++++ 11 files changed, 520 insertions(+) create mode 100644 .gitignore create mode 100644 .tool-versions create mode 100644 Dockerfile create mode 100644 pom.xml create mode 100755 scripts/deploy-local.sh create mode 100644 src/main/resources/MessageResources.properties create mode 100644 src/main/webapp/WEB-INF/struts-config.xml create mode 100644 src/main/webapp/WEB-INF/validation.xml create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.jsp create mode 100644 src/main/webapp/pages/Welcome.jsp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..6301486 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +maven 3.9.6 +java graalvm-community-21.0.1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b1affcd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM docker.io/tomcat:9.0.87-jre21-temurin-jammy +COPY target/struts-blank.war /usr/local/tomcat/webapps/ + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ded6e57 --- /dev/null +++ b/pom.xml @@ -0,0 +1,53 @@ + + + + + + 4.0.0 + org.apache.struts + struts-blank + war + Struts Apps - Blank + 1.0.0 + + + + org.apache.struts + struts-taglib + 1.3.10 + + + javax.servlet + servlet-api + 2.3 + provided + + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + + + diff --git a/scripts/deploy-local.sh b/scripts/deploy-local.sh new file mode 100755 index 0000000..10b2006 --- /dev/null +++ b/scripts/deploy-local.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]})) +PROJECT_BASE_DIR=$(realpath $SCRIPT_DIR/..) + +APP_NAME=blank +CONTAINER_NAME=springing-struts1-$APP_NAME +DOCKER=$((which podman &> /dev/null) && echo podman || echo docker) + +main() { + build \ + && deploy_local +} + +build() { + (cd $PROJECT_BASE_DIR + mvn clean package -U + ) +} + +deploy_local() { + (cd $PROJECT_BASE_DIR + $DOCKER build -t $CONTAINER_NAME . \ + && $DOCKER rm -f $CONTAINER_NAME \ + && $DOCKER run -d \ + -p 8080:8080 \ + -p 5005:5005 \ + --name $CONTAINER_NAME \ + --env DEBUG_PORT=5005 \ + $CONTAINER_NAME + ) +} + +main diff --git a/src/main/resources/MessageResources.properties b/src/main/resources/MessageResources.properties new file mode 100644 index 0000000..a48defe --- /dev/null +++ b/src/main/resources/MessageResources.properties @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -- standard errors -- +errors.header= +# -- validator -- +errors.invalid={0} is invalid. +errors.maxlength={0} can not be greater than {1} characters. +errors.minlength={0} can not be less than {1} characters. +errors.range={0} is not in the range {1} through {2}. +errors.required={0} is required. +errors.byte={0} must be an byte. +errors.date={0} is not a date. +errors.double={0} must be an double. +errors.float={0} must be an float. +errors.integer={0} must be an integer. +errors.long={0} must be an long. +errors.short={0} must be an short. +errors.creditcard={0} is not a valid credit card number. +errors.email={0} is an invalid e-mail address. +# -- other -- +errors.cancel=Operation cancelled. +errors.detail={0} +errors.general=The process did not complete. Details should follow. +errors.token=Request could not be completed. Operation is not in sequence. +# -- welcome -- +welcome.title=Struts Blank Application +welcome.heading=Welcome! +welcome.message=To get started on your own application, copy the struts-blank.war to a new WAR file using the name for your application. Place it in your container's "webapp" folder (or equivalent), and let your container auto-deploy the application. Edit the skeleton configuration files as needed, restart your container, and you are on your way! (You can find the MessageResources.properties file with this message in the /WEB-INF/src folder.) diff --git a/src/main/webapp/WEB-INF/struts-config.xml b/src/main/webapp/WEB-INF/struts-config.xml new file mode 100644 index 0000000..513c0fa --- /dev/null +++ b/src/main/webapp/WEB-INF/struts-config.xml @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/validation.xml b/src/main/webapp/WEB-INF/validation.xml new file mode 100644 index 0000000..ca6645f --- /dev/null +++ b/src/main/webapp/WEB-INF/validation.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + +
+ + + + + + + mask + ^[0-9a-zA-Z]*$ + + +
+ +
+ + + + + + postalCode + ^[0-9a-zA-Z]*$ + + + +
+ + + + + + + mask + ^[0-9a-zA-Z]*$ + + +
+ +
+ +
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..62c1df2 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,50 @@ + + + + + + + Struts Blank Application + + + + action + org.apache.struts.action.ActionServlet + + config + /WEB-INF/struts-config.xml + + 2 + + + + + + action + *.do + + + + + + index.jsp + + + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..07da6b5 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,25 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> + + +<%-- + +Redirect default requests to Welcome global ActionForward. +By using a redirect, the user-agent will change address to match the path of our Welcome ActionForward. + +--%> diff --git a/src/main/webapp/pages/Welcome.jsp b/src/main/webapp/pages/Welcome.jsp new file mode 100644 index 0000000..b83e322 --- /dev/null +++ b/src/main/webapp/pages/Welcome.jsp @@ -0,0 +1,39 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> +<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> +<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> + + + +<bean:message key="welcome.title"/> + + + + + + + ERROR: Application resources not loaded -- check servlet container + logs for error messages. + + + +

+

+ + +
From 6e5419b15477c48134caa3a13ddb163ca392631f Mon Sep 17 00:00:00 2001 From: Iwauo Tajima Date: Tue, 1 Apr 2025 04:38:33 +0900 Subject: [PATCH 2/2] migrate to springboot based app --- .dockerignore | 4 +++ .gitignore | 1 + .tool-versions | 2 -- Dockerfile | 10 +++++-- README.md | 2 +- entrypoint.sh | 13 +++++++++ mise.toml | 3 ++ pom.xml | 61 +++++++++++++++++------------------------ scripts/deploy-local.sh | 34 ----------------------- scripts/start.sh | 47 +++++++++++++++++++++++++++++++ 10 files changed, 102 insertions(+), 75 deletions(-) create mode 100644 .dockerignore delete mode 100644 .tool-versions create mode 100755 entrypoint.sh create mode 100644 mise.toml delete mode 100755 scripts/deploy-local.sh create mode 100755 scripts/start.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a5ac5dc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +* +!/entrypoint.sh +!/target/extracted + diff --git a/.gitignore b/.gitignore index 2f7896d..07827cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/ +.idea/ \ No newline at end of file diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 6301486..0000000 --- a/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -maven 3.9.6 -java graalvm-community-21.0.1 diff --git a/Dockerfile b/Dockerfile index b1affcd..5414c67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,9 @@ -FROM docker.io/tomcat:9.0.87-jre21-temurin-jammy -COPY target/struts-blank.war /usr/local/tomcat/webapps/ +FROM docker.io/azul/zulu-openjdk:21.0.1-21.30.15 +WORKDIR /app +COPY target/extracted/dependencies/ ./ +COPY target/extracted/spring-boot-loader/ ./ +COPY target/extracted/snapshot-dependencies/ ./ +COPY target/extracted/application/ ./ +COPY entrypoint.sh ./ +ENTRYPOINT ["./entrypoint.sh"] diff --git a/README.md b/README.md index 9aed515..3f6921d 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ How to run - Run the following command. ```bash -./scripts/deploy-local.sh +./scripts/start.sh ``` - Open the following URL with your browser. diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..d668ea8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +main() { + launch +} + +launch() { + java \ + ${DEBUG_PORT:+ -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:${DEBUG_PORT}} \ + "org.springframework.boot.loader.launch.WarLauncher" +} + +main \ No newline at end of file diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..1e69d92 --- /dev/null +++ b/mise.toml @@ -0,0 +1,3 @@ +[tools] +java = 'zulu-21.40.17' +maven = '3.9.9' diff --git a/pom.xml b/pom.xml index ded6e57..d27b343 100644 --- a/pom.xml +++ b/pom.xml @@ -1,23 +1,7 @@ - - - + 4.0.0 org.apache.struts @@ -25,29 +9,34 @@ war Struts Apps - Blank 1.0.0 - + + 21 + 21 + + + + local-repo + file:../mvn-repo + + - org.apache.struts - struts-taglib - 1.3.10 - - - javax.servlet - servlet-api - 2.3 - provided + io.github.iwauo.springing-struts + struts1-core + 0.0.4 - - ${project.artifactId} - org.apache.maven.plugins - maven-war-plugin - 3.4.0 + org.springframework.boot + spring-boot-maven-plugin + + springing.struts1.entrypoint.Main + WAR + 3.2.5 + - + - + \ No newline at end of file diff --git a/scripts/deploy-local.sh b/scripts/deploy-local.sh deleted file mode 100755 index 10b2006..0000000 --- a/scripts/deploy-local.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]})) -PROJECT_BASE_DIR=$(realpath $SCRIPT_DIR/..) - -APP_NAME=blank -CONTAINER_NAME=springing-struts1-$APP_NAME -DOCKER=$((which podman &> /dev/null) && echo podman || echo docker) - -main() { - build \ - && deploy_local -} - -build() { - (cd $PROJECT_BASE_DIR - mvn clean package -U - ) -} - -deploy_local() { - (cd $PROJECT_BASE_DIR - $DOCKER build -t $CONTAINER_NAME . \ - && $DOCKER rm -f $CONTAINER_NAME \ - && $DOCKER run -d \ - -p 8080:8080 \ - -p 5005:5005 \ - --name $CONTAINER_NAME \ - --env DEBUG_PORT=5005 \ - $CONTAINER_NAME - ) -} - -main diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100755 index 0000000..a31bb99 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -eu + +SCRIPT_DIR=$(realpath "$(dirname $BASH_SOURCE)") +PROJECT_BASE_DIR=$(realpath "$SCRIPT_DIR/..") + +APP_NAME=struts-blank +CONTAINER_NAME=springing-struts-$APP_NAME +DOCKER=$( (command -v podman &> /dev/null) && echo podman || echo docker ) + +main() { + build && start +} + +build() { + mvn \ + clean \ + dependency:purge-local-repository \ + -DreResolve=false \ + -DactTransitively=false \ + -DmanualInclude='io.github.iwauo.springing-struts' \ + package -U \ + spring-boot:repackage \ + && java \ + -Djarmode=layertools \ + -jar target/$APP_NAME-*.war \ + extract --destination target/extracted +} + +start() { + $DOCKER build -t $CONTAINER_NAME . \ + && ($DOCKER stop -t 0 $CONTAINER_NAME || true) \ + && $DOCKER rm -f $CONTAINER_NAME \ + && $DOCKER run -d \ + -p 8080:8080 \ + -p 5005:5005 \ + --name $CONTAINER_NAME \ + --env DEBUG_PORT=5005 \ + $CONTAINER_NAME \ + && $DOCKER logs -f $CONTAINER_NAME +} + +(cd "$PROJECT_BASE_DIR" \ + && eval "$(mise env)" \ + && main +) \ No newline at end of file