My project is in Java EE. I got two modules war and ejb. When I remove stripes jar from libraries of ejb module and include it to war module Localizable error works fine.
But when I did that war module cant connect to ejb session bean(I'm using stripes-injection-enricher).
Project sees the StripesResources.properties file because I can get string like that in jsp file:
<fmt:message key="layout.otherLanguage"/>
in resources I got:
layout.otherLanguage=French
it works. But LocalizableError or SimpleError not working in actionbean file:
errors.add("username",
new LocalizableError("primaryEmailNotFound"));
In resources file:
project.action.LoginActionBean.primaryEmailNotFound=wrong login
What can I do?
The problem was solved when I delete stripes.jar from ejb module and deploy .war file instead of .ear file.
Related
I created a Spring Boot Application using Spring Initilizr. I then included Apache's Freemarker template engine to load the templates from my project. The engine by default loads templates from: src/main/resources/templates/ folder.
I am trying to load a simple index.ftl file as template when the user visits the webpage http://localhost:8080. But I need to load the templates from src/main/webapp/ folder. Whenever I try to load the templates from outside the resources folder, the template engine fails to find the templates.
I have gone through various tutorials and Stack Overflow questions. None answer my question and I'm stuck with a 404 ERROR because the engine is not able to find the files.
The file structure is:
|-src
|---main
|-----java
|-------MainApplication.java
|-------controllers
|---------ViewController.java
|-----resources
|-------static
|-------templates
|-------application.properties
|-----webapp
|-------index.ftl
After a lot of digging, I came across a post where they suggested changing the location where the template engine searches the files. It suggested adding following lines in application.properties:
spring.freemarker.enabled=true
spring.freemarker.template-loader-path=classpath:src/main/webapp/
This doesn't seem to work at all.
I am trying to resolve simple index page when I visit the webpage at http://localhost:8080. I've written following code for mapping the HTTP request in ViewController.java:
#RequestMapping("/")
public ModelAndView home(Model model)
{
return new ModelAndView("index");
}
No idea if I am totally getting it wrong or I've missed some configuration.
From Spring docs:
Do not use the src/main/webapp directory if your application is
packaged as a jar. Although this directory is a common standard, it
works only with war packaging, and it is silently ignored by most
build tools when you generate a war.
src/main/webapp is associated with web archive and will be packaged by maven war plugin when you generate the war.
Assuming you require a separate location to keep ftl templates and you would still like to package as jar you could follow below steps.
Add the resource entry in the build in pom file so resource plugin can copy that directory to classpath.
<build>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resources>
<build>
Change the loader path to read from the ROOT of classpath.
spring.freemarker.template-loader-path=classpath:
If its only for ftl templates I would change the directory to src/main/ftls to avoid confusion and update the same in the resources.
UPDATE
I actually wanted to build a WAR deployment package
You have to use war plugin to build war. Add the plugin and change the packaging to war in pom.
More about the Traditional Deployment: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file
EDIT
In embedded tomcat you can define static resources path in application-properties
spring.mvc.static-path-pattern=
If you deploy to tomcat, in tomcat use can define inside server.xml static context that can hold freemarker files, as
<Context docBase="/home/stuff" path="/static" />
A <Context> element is added inside the <Host> element. Context has two attributes: docBase is the directory on disk that contains your static files and path is the URL that you want to serve the files on.
I am currently using intellij for my java code. When i try to run the Project, it throws the below error.
2016-06-21 09:19:46.691::INFO: jetty-6.1.14
2016-06-21 09:19:46.843::WARN: Web application not found src/main/webapp
2016-06-21 09:19:46.843::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext#359d136a{/admin,src/main/webapp}
java.io.FileNotFoundException: src/main/webapp
In RUN >> Edit Configurations, Working directory $MODULE_WORKING_DIR$
Example
Did you add the folder "webapp" to your classpath/resources-folder?
I guess you have something like:
applicationContext.setBaseResource(Resource.newClassPathResource("webapp", true, true));
In your WebAppContext-configuration - so, just add a folder named "webapp" under "src/main/resources/." and I guess it should be working as intended.
I`m developing client that uses library Overthere 2.3.1. With local machine client works perfectly. But when I try to call same code included to EJB 3.0, I've got exception that not all required classes have been loaded.
I`ve looked over the source and found that the class contains Protocol annotation scanner (https://github.com/hierynomus/scannit) with hardcoded class name:
Scannit scannit = new Scannit(Configuration.config()
.scan("com.xebialabs")
.with(new AbstractScanner[] { new TypeAnnotationScanner() }));
The command
Thread.currentThread().getContextClassLoader().getResources("com/xebialabs")
returns null.
Looks like EJB runs in a separate classloader which does not have access to all the jars.
The EJB is packed to EAR with following structure:
EAR
--META-INF
----sda-dd.xml
----SAP_MANIFEST.MF
----MANIFEST.MF
----application-j2ee-engine.xml
--ejb.jar
--extlibs.jars
The MANIFEST.MF file don`t contain any referenses to external libs in CLASS-PATH. The EAR project is deployed to Application server successfully.
The EJB.jar also contains META-INF/MANIFEST.MF with value "Class-Path: ." by default.
I`ve already tried playing around with CLASS-PATH in manifest files, but have no luck.
Could anyone help me, how to build project with all external libs to be loaded while EJB runs? What have I missed with resources and classloaders?
I have a maven multi-module project.
project-services (service layer..above the dao layer)
project-controller (My Action classes sits in this module)
project-web (all jsps, view artificats)
The issue is I have a valid DefaultProjectsAction-validation.xml in the package with DefaultProjectsAction.java as well as the properties file.
All these modules, when the war file is deployed will be in /WEB-INF/lib. I use in struts.xml the default package. All files are correctly set-up. Spellings errors on the the file names checked properly. Will my struts validations work if the validation xml files are in a seperate jar. I read somewhere where they say it should be in WEB-INF/classes/. Is this the reason why my struts form can't be validated?
Ok it's exactly 48 hours since I started looking at this problem and ladies and gentlemen the solution has been found.
Putting struts 2 action classes on a seperate module and validation set-up has to go like this.
project-controller (will have action classes for Struts 2 in this case)
- com.pack.UserAction.java
The solution is to create a source folder src/main/resources/com/pack (Maven project) in project-web module and put UserAction-validation.xml in there. Like this
project-web (views, jsps, properties files and set-up files)
- src/main/resources/com/pack/UserAction-validation.xml
The file will be copied to /WEB-INF/classes/com/pack (The action class package should form the path) and on building the project
I have a openJPA based project that I need to deploy it in format of aar into the following folder under Tomcat.
tomcat\webapps\axis2\WEB-INF\services
But it seems that the service cannot load the persistence.xml file in the META-INF folder within the aar file. I found a solution to rename the aar file into jar, like DummySerivce.aar -> DummySerivce.jar and then put the DummySerivce.jar into the lib folder, to be exactly
tomcat\webapps\axis2\WEB-INF\lib
This time, the persistence.xml could be loaded and the service worked well. But this unnecessarily imported a jar file which was not included in the specification.
So my question is, is there any way to load the persistence.xml from a aar file? is it possible to overload the path of persistence.xml file in code?
btw, only entity information are left in the persistence.xml, database connection parameters are already define in code, and I'm using Axis2.
Thanks!
I have found a solution.
By adding the following line into the services.xml, persistence.xml packed in aar file could be successfully loaded.
<parameter name="ServiceTCCL">composite</parameter>
for detailed info. please refer to http://wso2.org/node/1131
Now checking if there's any side effect.
TCCL - Thread context class loader
default - Status quo, normal behavior
composite - TCCL contains all
jars from environment (say webapp) and those specified in the
service
archive (aar) file under /lib service - TCCL contains all jars from
service archive (aar)