When I deploy and run the application from eclipse everything works fine, but when I try to generate manually WAR file I have problems.
I entered application root folder. Open terminal and wrote:
jar -cvf forum.war *
It generates war file with this log:
added manifest
adding: build/(in = 0) (out= 0)(stored 0%)
adding: build/classes/(in = 0) (out= 0)(stored 0%)
adding: build/classes/controller/(in = 0) (out= 0)(stored 0%)
adding: build/classes/controller/SInitialize.class(in = 1382) (out= 686)(deflated 50%)
adding: build/classes/controller/Utils.class(in = 2638) (out= 1274)(deflated 51%)
adding: build/classes/controller/DataManager.class(in = 25910) (out= 8912)(deflated 65%)
adding: build/classes/model/(in = 0) (out= 0)(stored 0%)
adding: build/classes/model/enums/(in = 0) (out= 0)(stored 0%)
adding: build/classes/model/enums/Role.class(in = 979) (out= 547)(deflated 44%)
adding: build/classes/model/enums/TopicType.class(in = 1009) (out= 551)(deflated 45%)
adding: build/classes/model/enums/MessageType.class(in = 979) (out= 530)(deflated 45%)
adding: build/classes/beans/(in = 0) (out= 0)(stored 0%)
adding: build/classes/beans/Comments.class(in = 4523) (out= 2126)(deflated 52%)
adding: build/classes/beans/TopicRatings$Key.class(in = 1525) (out= 767)(deflated 49%)
adding: build/classes/beans/Content.class(in = 258) (out= 192)(deflated 25%)
adding: build/classes/beans/TopicRatings.class(in = 2853) (out= 1250)(deflated 56%)
adding: build/classes/beans/Comment.class(in = 4993) (out= 1941)(deflated 61%)
adding: build/classes/beans/UserChangeRoleBean.class(in = 786) (out= 431)(deflated 45%)
adding: build/classes/beans/SignUpBean.class(in = 1611) (out= 614)(deflated 61%)
adding: build/classes/beans/CommentRatings.class(in = 2897) (out= 1255)(deflated 56%)
adding: build/classes/beans/Messages.class(in = 2589) (out= 1139)(deflated 56%)
adding: build/classes/beans/TopicBean.class(in = 3877) (out= 1482)(deflated 61%)
adding: build/classes/beans/Users.class(in = 2689) (out= 1076)(deflated 59%)
adding: build/classes/beans/CommentRatings$Key.class(in = 1543) (out= 770)(deflated 50%)
adding: build/classes/beans/UserPublicBean.class(in = 2200) (out= 902)(deflated 59%)
adding: build/classes/beans/AvatarBean.class(in = 548) (out= 315)(deflated 42%)
adding: build/classes/beans/TopicRating.class(in = 1027) (out= 529)(deflated 48%)
adding: build/classes/beans/CommentDeleteBean.class(in = 530) (out= 317)(deflated 40%)
adding: build/classes/beans/Subforum.class(in = 3261) (out= 1241)(deflated 61%)
adding: build/classes/beans/EditProfileBean.class(in = 1148) (out= 477)(deflated 58%)
adding: build/classes/beans/User.class(in = 5952) (out= 2255)(deflated 62%)
adding: build/classes/beans/TopicNewBean.class(in = 1461) (out= 621)(deflated 57%)
adding: build/classes/beans/CommentSubmitBean.class(in = 1028) (out= 499)(deflated 51%)
adding: build/classes/beans/Message.class(in = 2345) (out= 995)(deflated 57%)
adding: build/classes/beans/LoginBean.class(in = 870) (out= 409)(deflated 52%)
adding: build/classes/beans/Topics.class(in = 2150) (out= 920)(deflated 57%)
adding: build/classes/beans/SearchBean.class(in = 1338) (out= 616)(deflated 53%)
adding: build/classes/beans/SubforumNewBean.class(in = 1282) (out= 569)(deflated 55%)
adding: build/classes/beans/CommentRating.class(in = 1180) (out= 595)(deflated 49%)
adding: build/classes/beans/Subforums.class(in = 4741) (out= 2333)(deflated 50%)
adding: build/classes/beans/services/(in = 0) (out= 0)(stored 0%)
adding: build/classes/beans/Topic.class(in = 4183) (out= 1595)(deflated 61%)
adding: build/classes/beans/MessageBean.class(in = 845) (out= 427)(deflated 49%)
adding: build/classes/beans/CommentLikeBean.class(in = 716) (out= 379)(deflated 47%)
adding: build/classes/beans/TopicRatingBean.class(in = 710) (out= 376)(deflated 47%)
adding: build/classes/beans/CommentEditBean.class(in = 1025) (out= 497)(deflated 51%)
adding: build/classes/services/(in = 0) (out= 0)(stored 0%)
adding: build/classes/services/HomePageService.class(in = 29395) (out= 12215)(deflated 58%)
adding: build/classes/services/LoginService.class(in = 6099) (out= 2895)(deflated 52%)
adding: Projektni Zadatak WEB.pdf(in = 534171) (out= 515168)(deflated 3%)
adding: src/(in = 0) (out= 0)(stored 0%)
adding: src/controller/(in = 0) (out= 0)(stored 0%)
adding: src/controller/SInitialize.java(in = 2274) (out= 699)(deflated 69%)
adding: src/controller/Utils.java(in = 1238) (out= 412)(deflated 66%)
adding: src/controller/DataManager.java(in = 23435) (out= 2352)(deflated 89%)
adding: src/model/(in = 0) (out= 0)(stored 0%)
adding: src/model/enums/(in = 0) (out= 0)(stored 0%)
adding: src/model/enums/TopicType.java(in = 67) (out= 66)(deflated 1%)
adding: src/model/enums/MessageType.java(in = 66) (out= 64)(deflated 3%)
adding: src/model/enums/Role.java(in = 67) (out= 66)(deflated 1%)
adding: src/beans/(in = 0) (out= 0)(stored 0%)
adding: src/beans/SubforumNewBean.java(in = 841) (out= 284)(deflated 66%)
adding: src/beans/UserPublicBean.java(in = 1623) (out= 450)(deflated 72%)
adding: src/beans/Messages.java(in = 1484) (out= 452)(deflated 69%)
adding: src/beans/UserChangeRoleBean.java(in = 420) (out= 214)(deflated 49%)
adding: src/beans/Subforum.java(in = 2515) (out= 571)(deflated 77%)
adding: src/beans/Users.java(in = 1706) (out= 525)(deflated 69%)
adding: src/beans/TopicNewBean.java(in = 974) (out= 306)(deflated 68%)
adding: src/beans/SignUpBean.java(in = 1090) (out= 341)(deflated 68%)
adding: src/beans/SearchBean.java(in = 674) (out= 270)(deflated 59%)
adding: src/beans/CommentDeleteBean.java(in = 269) (out= 154)(deflated 42%)
adding: src/beans/Message.java(in = 1623) (out= 476)(deflated 70%)
adding: src/beans/EditProfileBean.java(in = 712) (out= 246)(deflated 65%)
adding: src/beans/TopicRatings.java(in = 2193) (out= 651)(deflated 70%)
adding: src/beans/User.java(in = 4974) (out= 1104)(deflated 77%)
adding: src/beans/LoginBean.java(in = 505) (out= 180)(deflated 64%)
adding: src/beans/Content.java(in = 42) (out= 44)(deflated -4%)
adding: src/beans/TopicRating.java(in = 711) (out= 275)(deflated 61%)
adding: src/beans/CommentEditBean.java(in = 582) (out= 242)(deflated 58%)
adding: src/beans/AvatarBean.java(in = 240) (out= 147)(deflated 38%)
adding: src/beans/CommentLikeBean.java(in = 378) (out= 162)(deflated 57%)
adding: src/beans/Topics.java(in = 1244) (out= 432)(deflated 65%)
adding: src/beans/MessageBean.java(in = 531) (out= 225)(deflated 57%)
adding: src/beans/CommentRatings.java(in = 2421) (out= 694)(deflated 71%)
adding: src/beans/Topic.java(in = 3199) (out= 858)(deflated 73%)
adding: src/beans/CommentRating.java(in = 735) (out= 272)(deflated 62%)
adding: src/beans/Subforums.java(in = 2796) (out= 969)(deflated 65%)
adding: src/beans/services/(in = 0) (out= 0)(stored 0%)
adding: src/beans/Comments.java(in = 3507) (out= 1004)(deflated 71%)
adding: src/beans/TopicRatingBean.java(in = 366) (out= 161)(deflated 56%)
adding: src/beans/TopicBean.java(in = 2920) (out= 769)(deflated 73%)
adding: src/beans/CommentSubmitBean.java(in = 589) (out= 256)(deflated 56%)
adding: src/beans/Comment.java(in = 3914) (out= 901)(deflated 76%)
adding: src/services/(in = 0) (out= 0)(stored 0%)
adding: src/services/HomePageService.java(in = 34676) (out= 5734)(deflated 83%)
adding: src/services/LoginService.java(in = 6275) (out= 1668)(deflated 73%)
adding: WebContent/(in = 0) (out= 0)(stored 0%)
adding: WebContent/profile_messages.html(in = 915) (out= 368)(deflated 59%)
adding: WebContent/WEB-INF/(in = 0) (out= 0)(stored 0%)
adding: WebContent/WEB-INF/lib/(in = 0) (out= 0)(stored 0%)
adding: WebContent/WEB-INF/lib/osgi-resource-locator-1.0.1.jar(in = 20235) (out= 17146)(deflated 15%)
adding: WebContent/WEB-INF/lib/jersey-server-2.25.jar(in = 940762) (out= 812861)(deflated 13%)
adding: WebContent/WEB-INF/lib/validation-api-1.1.0.Final.jar(in = 63777) (out= 47579)(deflated 25%)
adding: WebContent/WEB-INF/lib/persistence-api-1.0.jar(in = 52150) (out= 40983)(deflated 21%)
adding: WebContent/WEB-INF/lib/jstl.jar(in = 20682) (out= 17453)(deflated 15%)
adding: WebContent/WEB-INF/lib/asm-all-repackaged-2.2.0.jar(in = 401855) (out= 379036)(deflated 5%)
adding: WebContent/WEB-INF/lib/el-api.jar(in = 46158) (out= 42497)(deflated 7%)
adding: WebContent/WEB-INF/lib/mimepull-1.9.3.jar(in = 62135) (out= 56687)(deflated 8%)
adding: WebContent/WEB-INF/lib/jersey-container-servlet-core-2.25.jar(in = 66121) (out= 55570)(deflated 15%)
adding: WebContent/WEB-INF/lib/jackson-xc-1.9.13.jar(in = 27084) (out= 24875)(deflated 8%)
adding: WebContent/WEB-INF/lib/jersey-container-servlet-2.25.jar(in = 18101) (out= 14346)(deflated 20%)
adding: WebContent/WEB-INF/lib/standard.jar(in = 393259) (out= 351113)(deflated 10%)
adding: WebContent/WEB-INF/lib/javax.inject-2.2.0.jar(in = 5968) (out= 4533)(deflated 24%)
adding: WebContent/WEB-INF/lib/jersey-guava-2.8.jar(in = 962807) (out= 817752)(deflated 15%)
adding: WebContent/WEB-INF/lib/jersey-media-json-jackson-2.0-m07.jar(in = 5808) (out= 4190)(deflated 27%)
adding: WebContent/WEB-INF/lib/javax.servlet-api-3.0.1.jar(in = 85353) (out= 75030)(deflated 12%)
adding: WebContent/WEB-INF/lib/javassist-3.18.1-GA.jar(in = 714194) (out= 664822)(deflated 6%)
adding: WebContent/WEB-INF/lib/jaxb-api-2.2.7.jar(in = 100146) (out= 85972)(deflated 14%)
adding: WebContent/WEB-INF/lib/aopalliance-repackaged-2.2.0.jar(in = 14867) (out= 9865)(deflated 33%)
adding: WebContent/WEB-INF/lib/org.osgi.core-4.2.0.jar(in = 246924) (out= 222018)(deflated 10%)
adding: WebContent/WEB-INF/lib/jersey-client-2.25.jar(in = 168990) (out= 149270)(deflated 11%)
adding: WebContent/WEB-INF/lib/hk2-locator-2.5.0-b42.jar(in = 189454) (out= 176297)(deflated 6%)
adding: WebContent/WEB-INF/lib/jsp-api.jar(in = 88689) (out= 79782)(deflated 10%)
adding: WebContent/WEB-INF/lib/jackson-core-asl-1.9.13.jar(in = 232248) (out= 215037)(deflated 7%)
adding: WebContent/WEB-INF/lib/jackson-mapper-asl-1.9.13.jar(in = 780664) (out= 697674)(deflated 10%)
adding: WebContent/WEB-INF/lib/jersey-common-2.25.jar(in = 715934) (out= 631918)(deflated 11%)
adding: WebContent/WEB-INF/lib/jackson-jaxrs-1.9.13.jar(in = 18336) (out= 16451)(deflated 10%)
adding: WebContent/WEB-INF/lib/javax.ws.rs-api-2.0.jar(in = 112758) (out= 96456)(deflated 14%)
adding: WebContent/WEB-INF/lib/javax.annotation-api-1.2.jar(in = 26366) (out= 23303)(deflated 11%)
adding: WebContent/WEB-INF/lib/hk2-utils-2.5.0-b42.jar(in = 135317) (out= 119260)(deflated 11%)
adding: WebContent/WEB-INF/lib/hk2-api-2.5.0-b42.jar(in = 186763) (out= 162978)(deflated 12%)
adding: WebContent/WEB-INF/lib/jersey-media-multipart-2.25.jar(in = 67855) (out= 57758)(deflated 14%)
adding: WebContent/WEB-INF/web.xml(in = 1350) (out= 494)(deflated 63%)
adding: WebContent/login_dialog.html(in = 4109) (out= 732)(deflated 82%)
adding: WebContent/profile_manage_users.html(in = 516) (out= 202)(deflated 60%)
adding: WebContent/subforum.html(in = 2233) (out= 906)(deflated 59%)
adding: WebContent/topic_new.html(in = 2712) (out= 743)(deflated 72%)
adding: WebContent/subforum_new.html(in = 1854) (out= 571)(deflated 69%)
adding: WebContent/profile_menu.html(in = 547) (out= 199)(deflated 63%)
adding: WebContent/js/(in = 0) (out= 0)(stored 0%)
adding: WebContent/js/jquery.js(in = 282765) (out= 84245)(deflated 70%)
adding: WebContent/js/controller.js(in = 29245) (out= 4858)(deflated 83%)
adding: WebContent/js/upload_file.js(in = 4782) (out= 1567)(deflated 67%)
adding: WebContent/js/jquery.min.js(in = 84345) (out= 29551)(deflated 64%)
adding: WebContent/js/homepage.js(in = 42324) (out= 7178)(deflated 83%)
adding: WebContent/js/bootstrap-select.js(in = 68137) (out= 15285)(deflated 77%)
adding: WebContent/js/authenticate.js(in = 3818) (out= 1080)(deflated 71%)
adding: WebContent/search.html(in = 2060) (out= 876)(deflated 57%)
adding: WebContent/homepage.html(in = 2114) (out= 888)(deflated 57%)
adding: WebContent/data/(in = 0) (out= 0)(stored 0%)
adding: WebContent/META-INF/(in = 0) (out= 0)(stored 0%)
adding: WebContent/META-INF/MANIFEST.MF(in = 39) (out= 41)(deflated -5%)
adding: WebContent/profile.html(in = 2299) (out= 899)(deflated 60%)
adding: WebContent/profile_logged_user.html(in = 2808) (out= 665)(deflated 76%)
adding: WebContent/topic.html(in = 2090) (out= 862)(deflated 58%)
adding: WebContent/profile_not_logged_user.html(in = 279) (out= 137)(deflated 50%)
adding: WebContent/css/(in = 0) (out= 0)(stored 0%)
adding: WebContent/css/bootstrap-select.css(in = 7768) (out= 1694)(deflated 78%)
adding: WebContent/css/homepage.css(in = 6084) (out= 1911)(deflated 68%)
adding: WebContent/menu.html(in = 3385) (out= 1216)(deflated 64%)
adding: WebContent/resources/(in = 0) (out= 0)(stored 0%)
adding: WebContent/resources/forum.png(in = 1103) (out= 1108)(deflated 0%)
adding: WebContent/resources/cars.jpg(in = 2944) (out= 2793)(deflated 5%)
adding: WebContent/resources/slon.jpg(in = 3501) (out= 3368)(deflated 3%)
adding: WebContent/resources/lav.jpg(in = 2321) (out= 2310)(deflated 0%)
adding: WebContent/resources/sport.png(in = 17511) (out= 17514)(deflated 0%)
adding: WebContent/resources/drvo.jpg(in = 2831) (out= 2693)(deflated 4%)
adding: WebContent/resources/cvet.jpg(in = 3697) (out= 3556)(deflated 3%)
I copied it to tomcat's webapps folder and started the server. I couldn't find the application on: localhost:8080/forum/homepage.html. Still I found it on: localhost:8080/forum/WebContent/homepage.html but I have problems with rest service since I target localhost:8080/forum/WebContent/rest/authenticate.
This is content of my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>RESTApp</display-name>
<welcome-file-list>
<welcome-file>homepage.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>services,org.codehaus.jackson.jaxrs</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
How to generate WAR properly so I don't have WebContent in my url?
UPDATE:
Loggs from access.log:
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:15 +0100] "GET /forum/ HTTP/1.1" 302 -
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:15 +0100] "GET /forum/ HTTP/1.1" 404 963
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:22 +0100] "GET /forum/homepage.html HTTP/1.1" 404 989
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/homepage.html HTTP/1.1" 200 2114
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/css/bootstrap-select.css HTTP/1.1" 200 7768
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/js/bootstrap-select.js HTTP/1.1" 200 68137
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/js/jquery.js HTTP/1.1" 200 282765
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/css/homepage.css HTTP/1.1" 200 6084
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/js/authenticate.js HTTP/1.1" 200 3818
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/js/homepage.js HTTP/1.1" 200 42324
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/js/controller.js HTTP/1.1" 200 29245
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/rest/authenticate/get_logged_user HTTP/1.1" 404 1051
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:31 +0100] "GET /forum/WebContent/login_dialog.html HTTP/1.1" 200 4109
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:32 +0100] "GET /forum/WebContent/css/bootstrap-select.css.map HTTP/1.1" 404 1041
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:40 +0100] "GET /forum/WebContent/menu.html HTTP/1.1" 200 3385
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:40 +0100] "GET /forum/WebContent/rest/homepage/subforums HTTP/1.1" 404 1031
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:03:40 +0100] "GET /forum/WebContent/resources/forum.png HTTP/1.1" 200 1103
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:38 +0100] "GET /forum/homepage.html HTTP/1.1" 404 989
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/css/bootstrap-select.css HTTP/1.1" 200 7768
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/css/homepage.css HTTP/1.1" 200 6084
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/js/jquery.js HTTP/1.1" 200 282765
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/js/authenticate.js HTTP/1.1" 200 3818
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/js/homepage.js HTTP/1.1" 200 42324
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/js/controller.js HTTP/1.1" 200 29245
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:42 +0100] "GET /forum/WebContent/js/bootstrap-select.js HTTP/1.1" 200 68137
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:43 +0100] "GET /forum/WebContent/rest/authenticate/get_logged_user HTTP/1.1" 404 1051
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:43 +0100] "GET /forum/WebContent/login_dialog.html HTTP/1.1" 200 4109
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:43 +0100] "GET /forum/WebContent/css/bootstrap-select.css.map HTTP/1.1" 404 1041
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:51 +0100] "GET /forum/WebContent/menu.html HTTP/1.1" 200 3385
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:51 +0100] "GET /forum/WebContent/rest/homepage/subforums HTTP/1.1" 404 1031
0:0:0:0:0:0:0:1 - - [06/Feb/2018:19:35:51 +0100] "GET /forum/WebContent/resources/forum.png HTTP/1.1" 200 1103
The structure of the WAR you get is incorrect. It must contain WEB-INF
directory in its root 'directory' (and not in WebContent
directory). Also, classes must go to WEB-INF/classes
and not to build/classes
. src
is usually not included, although it should not harm.
I'd suggest to use some build tool. That could be Maven 3, for instance. An example can be found here: https://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
For maven project, you just do mvn package
and it builds your project for you: compiles, builds jars, then war.
If you prefer ant
, take a look at https://ant.apache.org/manual/Tasks/war.html