Velocity ResourceNotFoundException when mavenizing - maven-plugin

I have two projects called Generator and Executor ( both maven projects ). I make use of apache velocity template engine to generate ( in Generator ) and the code generated, gets executed in Executor. I want the code to run from Executor project. I have added Generator as dependency and was able to run successfully by specifying absolute paths for Template files that are required while executing.
I wanted to set the template path as relative to classpaths and execute the maven command. I tried everything as said in stackoverflow queries but I guess I am definitely missing something to run maven clean install successfully.
VelocityEngine Velocity = new VelocityEngine();
Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
Velocity.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName());
Velocity.setProperty("classpath.resource.loader.path",templatepath);
The above it the snippet of setting my Velocity Engine.
templatepath = Templates\\ -> Set relative to classpath ( src/main/resources )
I get the templates as
Template body = Velocity.getTemplate(xmlparsepath);
where xmlparsepath=XMLParse.vm
Expected program flow: I need to run **mvn clean exec:java test ** from Executor project which should execute Generator project ( which generates junit test cases in executor ) and run test cases in Executor project.
I get ResourceNotFoundExceptions saying that I am unable to point to template files. But the velocity logs say the otherwise. The Velocity logs in Generator project is as below.
2014-07-30 10:52:00,219 - Log4JLogChute initialized using file 'velocity.log'
2014-07-30 10:52:00,219 - Initializing Velocity, Calling init()...
2014-07-30 10:52:00,219 - Starting Apache Velocity v1.7 (compiled: 2010-11-19 12:14:37)
2014-07-30 10:52:00,219 - Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
2014-07-30 10:52:00,219 - Trying to use logger class org.apache.velocity.runtime.log.AvalonLogChute
2014-07-30 10:52:00,219 - Target log system for org.apache.velocity.runtime.log.AvalonLogChute is not available (java.lang.NoClassDefFoundError: org/apache/log/format/Formatter). Falling back to next log system...
2014-07-30 10:52:00,219 - Trying to use logger class org.apache.velocity.runtime.log.Log4JLogChute
2014-07-30 10:52:00,219 - Using logger class org.apache.velocity.runtime.log.Log4JLogChute
2014-07-30 10:52:00,235 - ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2014-07-30 10:52:00,266 - ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
2014-07-30 10:52:00,266 - Loaded System Directive: org.apache.velocity.runtime.directive.Stop
2014-07-30 10:52:00,266 - Loaded System Directive: org.apache.velocity.runtime.directive.Define
2014-07-30 10:52:00,266 - Loaded System Directive: org.apache.velocity.runtime.directive.Break
2014-07-30 10:52:00,266 - Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
2014-07-30 10:52:00,266 - Loaded System Directive: org.apache.velocity.runtime.directive.Literal
2014-07-30 10:52:00,266 - Loaded System Directive: org.apache.velocity.runtime.directive.Macro
2014-07-30 10:52:00,281 - Loaded System Directive: org.apache.velocity.runtime.directive.Parse
2014-07-30 10:52:00,281 - Loaded System Directive: org.apache.velocity.runtime.directive.Include
2014-07-30 10:52:00,281 - Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
2014-07-30 10:52:00,344 - Created '20' parsers.
2014-07-30 10:52:00,360 - Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm
2014-07-30 10:52:00,360 - Could not load resource 'VM_global_library.vm' from ResourceLoader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader: ClasspathResourceLoader Error: cannot find resource VM_global_library.vm
2014-07-30 10:52:00,360 - Velocimacro : Default library not found.
2014-07-30 10:52:00,360 - Velocimacro : allowInline = true : VMs can be defined inline in templates
2014-07-30 10:52:00,360 - Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
2014-07-30 10:52:00,360 - Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
2014-07-30 10:52:00,360 - Velocimacro : autoload off : VM system will not automatically reload global library macros
2014-07-30 10:52:00,391 - ResourceManager : found Templates\RootTemplate.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2014-07-30 10:52:00,391 - ResourceManager : found Templates\XMLParse.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2014-07-30 10:52:00,391 - ResourceManager : found Templates\XMLHeader.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2014-07-30 10:52:00,391 - ResourceManager : found Templates\XMLFooter.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2014-07-30 10:52:00,391 - ResourceManager : found Templates\\PackagesTemplate.vm with loader
Velocity logs pertaining to Executor Project.
2014-07-30 14:43:48,502 - Log4JLogChute initialized using file 'velocity.log'
2014-07-30 14:43:48,503 - Initializing Velocity, Calling init()...
2014-07-30 14:43:48,503 - Starting Apache Velocity v1.7 (compiled: 2010-11-19 12:14:37)
2014-07-30 14:43:48,503 - Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
2014-07-30 14:43:48,503 - Trying to use logger class org.apache.velocity.runtime.log.AvalonLogChute
2014-07-30 14:43:48,503 - Target log system for org.apache.velocity.runtime.log.AvalonLogChute is not available (java.lang.NoClassDefFoundError: org/apache/log/format/Formatter). Falling back to next log system...
2014-07-30 14:43:48,503 - Trying to use logger class org.apache.velocity.runtime.log.Log4JLogChute
2014-07-30 14:43:48,503 - Using logger class org.apache.velocity.runtime.log.Log4JLogChute
2014-07-30 14:43:48,506 - ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2014-07-30 14:43:48,515 - ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
2014-07-30 14:43:48,516 - Loaded System Directive: org.apache.velocity.runtime.directive.Stop
2014-07-30 14:43:48,517 - Loaded System Directive: org.apache.velocity.runtime.directive.Define
2014-07-30 14:43:48,518 - Loaded System Directive: org.apache.velocity.runtime.directive.Break
2014-07-30 14:43:48,518 - Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
2014-07-30 14:43:48,518 - Loaded System Directive: org.apache.velocity.runtime.directive.Literal
2014-07-30 14:43:48,519 - Loaded System Directive: org.apache.velocity.runtime.directive.Macro
2014-07-30 14:43:48,520 - Loaded System Directive: org.apache.velocity.runtime.directive.Parse
2014-07-30 14:43:48,521 - Loaded System Directive: org.apache.velocity.runtime.directive.Include
2014-07-30 14:43:48,522 - Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
2014-07-30 14:43:48,545 - Created '20' parsers.
2014-07-30 14:43:48,549 - Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm
2014-07-30 14:43:48,549 - Could not load resource 'VM_global_library.vm' from ResourceLoader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader: ClasspathResourceLoader Error: cannot find resource VM_global_library.vm
2014-07-30 14:43:48,549 - Velocimacro : Default library not found.
2014-07-30 14:43:48,549 - Velocimacro : allowInline = true : VMs can be defined inline in templates
2014-07-30 14:43:48,549 - Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
2014-07-30 14:43:48,549 - Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
2014-07-30 14:43:48,549 - Velocimacro : autoload off : VM system will not automatically reload global library macros
2014-07-30 14:43:48,552 - ResourceManager : unable to find resource 'RootTemplate.vm' in any resource loader.
Thanks all in advance.

I am able to solve it guys. I was not making using of VM_global_library.vm. We need to load our templates into this field, something like below
prop.setProperty("velocimacro.library", "RootTemplate.vm" );
And the runtime engine was able to pick up templates this way.

Related

Spring AOP - Execution coverage

To what classes (in which packages) and methods does this execution apply?
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* com.my.application.service..*Manager.*(..))"/>
</aop:config>
I hade read about Spring AOP on http://spring.io/docs but can't understand the execution expression.
From the spring docs 10.2.3 section in link it is quite clear and execution is used to designate a pointcut.
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern) throws-pattern?)
modifiers-pattern - Method visibility (public, protected, private, *)
ret-type-pattern - Return type of the method
declaring-type-pattern - Package or class (ex: com.app.service.* - applies to all classes in this package, com.app.service.UserService - applies only to UserService class, * - all)
name-pattern - method name (ex: set* - all setters)
param-pattern - method parameters (.. - any number of parameters, java.lang.String - method taking String as parameter.
throws-pattern - Method throwing this exception.
In your case
expression="execution(* com.my.application.service..*Manager.*(..))"/>
you are designating this pointcut to all methods whose classname ends with Manager in com.my.application.service package & its sub-packages.

Launch and endpoint inside servicemix

What do I have to do to call Endpoint.publish from a bundle in servicemix?
I have used wsdl2java to create an impl that I launch inside a BundleActivator:
LOG.info("WSBundle registering using endpoint...");
endpointAddress = substituteParameters(endpointAddress, ref);
Endpoint endpoint = Endpoint.publish(endpointAddress, service);
myEndpoints.put(service, endpoint);
LOG.info("WSBundle registered server at: "+endpointAddress);
This works fine inside the Eclipse IDE but fails when I run the bundle inside the service mix deploy area.
At first the failure was due to missing some classes in the following packages:
javax.xml.ws,
javax.xml.ws.spi,
org.apache.cxf.endpoint,
org.apache.cxf.frontend,
org.apache.cxf.jaxws,
org.apache.cxf.jaxws.spi,
After adding these to my manifest as imported packages I get the following error:
ERROR: Bundle WSExposer [187] EventDispatcher: Error during dispatch. (javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found)
javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found
at javax.xml.ws.spi.FactoryFinder$2.run(FactoryFinder.java:133)
at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:238)
at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:127)
at javax.xml.ws.spi.FactoryFinder.access$200(FactoryFinder.java:44)
at javax.xml.ws.spi.FactoryFinder$3.run(FactoryFinder.java:229)
at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:238)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:163)
at javax.xml.ws.spi.Provider.provider(Provider.java:43)
at javax.xml.ws.Endpoint.publish(Endpoint.java:57)
My manifest file is as follows:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: WSBundle
Bundle-SymbolicName: WSBundle
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.company.soa.wsbundle.WSExposerActivator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: com.company.product.history.filtertypes.v1,
com.company.product.system.basetypes.v1,
com.company.svc.product.event.v1,
com.company.svc.product.service.event.v1,
com.company.svc.product.service.faults.v1,
javax.xml.ws,
javax.xml.ws.spi,
org.apache.cxf.endpoint,
org.apache.cxf.frontend,
org.apache.cxf.jaxws,
org.apache.cxf.jaxws.spi,
org.osgi.framework
Export-Package: com.company.soa.wsbundle
I found that you can switch service mix to use the Equinox frame work which resolved the issue.
in the etc/config.properties change the karaf.framework to eclipse:
karaf.framework=equinox

How to understand chats.html v.s ('/getchats', ChatsRequestHandler)]

I try to understand the different between:
The class ChatsRequestHandler generate a template with the name chats.html
template = self.generate('chats.html', template_values)
In the application view its is named getchats:
application = webapp.WSGIApplication(
[('/', MainRequestHandler),
('/getchats', ChatsRequestHandler)],
The same occurs to me at edit_user.html v.s ('/edituser', EditUserProfileHandler)
How is it that the application knows that the getchats is connected to the chats.html aldo they have not the same name? I would expect that it should be the same name chats.html and ('/chats', ChatsRequestHandler).
The flow of your request goes something like this.
App Engine looks up your app.yaml file. It should contain an entry that says /getchats should be handled by application in somefile.py.
It then goes to this "application view" and matches it to a Webapp Route. In this case, that route is ('/getchats', ChatsRequestHandler).
Then it calls get or post on ChatRequestHandler, passing it the request and response objects.
The output of that is sent back to the user's browser.
You are free to implement ChatRequestHandler as you'd like. In this case you're doing so by reading in a template named chats.html, populating it with some values, and then outputting it.
So the application knows that getchats is connected to ChatRequestHandler. The name of chats.html is pretty arbitrary - the ChatReqeustHandler has to know it, but that is all. You could rename it.
Thanks for helping me:
The example a came up with comes from codenvy.com as a examples app.
1 App Engine looks up your app.yaml file. It should contain an entry that says /getchats should be handled by application in somefile.py.
Here is the app.yaml file of this application
application: 3kus-apps
version: 1
runtime: python
api_version: 1
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /.*
script: devchat.py
So as you can see it contain's no entry that says /getchats should be handled by application in somefile.py.
What i found there is a util.js file witch has a function updateChat(). function updateChat() {downloadUrl(getRandomUrl("/getchats"), "GET", null, onChatsReturned);}.
However, I would like to know - under (1) how this should be handled by a somefile.py.

OpenEJB 4.5.1: NameNotFoundException

Its the first time I used the OpenEJB container system. When I use the lockup-Method of the InitialContext, I get a NameNotFoundException. I've read lots of examples and tutorials and in every example the lookup method looks like:
initialContext.lookup("NameOfBean");
Now I've found another solution which uses the lookup like the following code snippet which works for me too.
initialContext.lookup("java:global/classpath.ear/ProjectName/NameofBean");
The question is why the first version doesn't work for me and what I've done wrong?
Excerpts of the OpenEJB log:
INFO - ********************************************************************************
INFO - OpenEJB http://openejb.apache.org/
INFO - Startup: Sat Dec 22 13:17:59 CET 2012
INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved.
INFO - Version: 4.5.1
INFO - Build date: 20121209
INFO - Build time: 08:47
INFO - ********************************************************************************
INFO - openejb.home = D:\workspace\ProjectName
INFO - openejb.base = D:\workspace\ProjectName
INFO - Succeeded in installing singleton service
INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Using 'openejb.deployments.classpath.include=.*'
INFO - Found EjbModule in classpath: D:\workspace\ProjectName\build\classes
INFO - Searched 17 classpath urls in 2184 milliseconds. Average 128 milliseconds per url.
INFO - Beginning load: D:\workspace\ProjectName\build\classes
INFO - Configuring enterprise application: D:\workspace\ProjectName\classpath.ear
WARNUNG - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
INFO - Auto-deploying ejb NameOfBean: EjbDeployment(deployment-id=NameOfBean)
[... AUTHORS'S NOTE: SOME MORE BEANS]
INFO - Assembling app: D:\workspace\ProjectName\classpath.ear
INFO - Hibernate Validator 4.2.0.Final
INFO - Ignoring XML configuration.
JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested installation of a ClassFileTransformer which requires a JavaAgent. See http://openejb.apache.org/3.0/javaagent.html
INFO - OpenJPA dynamically loaded a validation provider.
INFO - Jndi(name=NameOfBeanRemote) --> Ejb(deployment-id=NameofBean)
INFO - Jndi(name=global/classpath.ear/ProjectName/NameOfBean!de.mypath.stateless.NameOfBeanInterface) --> Ejb(deployment-id=NameofBean)
INFO - Jndi(name=global/classpath.ear/ProjectName/NameofBean) --> Ejb(deployment-id=NameOfBean)
[... AUTHORS'S NOTE: SOME FOR OTHER BEANS]
INFO - OpenWebBeans Container is starting...
INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
INFO - All injection points are validated successfully.
INFO - OpenWebBeans Container has started, it took 250 ms.
INFO - Created Ejb(deployment-id=NameOfBean, ejb-name=NameOfBean, container=Default Stateless Container)
[... AUTHORS'S NOTE: SOME FOR OTHER BEANS]
INFO - Quartz scheduler 'OpenEJB-TimerService-Scheduler' initialized from an externally provided properties instance.
INFO - Quartz scheduler version: 2.1.6
INFO - Scheduler OpenEJB-TimerService-Scheduler_$_OpenEJB started.
INFO - Started Ejb(deployment-id=NameOfBean, ejb-name=NameOfBean, container=Default Stateless Container)
[... AUTHORS'S NOTE: SOME FOR OTHER BEANS]
This is my TestClass:
public class NamerOfBeanOpenEJBTest {
private static InitialContext initialContext;
#BeforeClass
public static void setUp() throws Exception {
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
properties.setProperty("openejb.deployments.classpath.include", ".*");
initialContext = new InitialContext(properties);
}
#Test
public void testBean() throws NamingException{
Object object = initialContext.lookup("java:global/classpath.ear/ProjectName/NameOfBean");
assertNotNull(object);
assertTrue(object instanceof NameOfBean);
}
#AfterClass
public static void afterClass() throws Exception {
if (initialContext != null) {
initialContext.close();
}}
}
Does someone have tipps or solutions for me?
Thanks a lot.
Edit:
In JBoss AS 7.1 the lookup can places like this example:
new InitialContext().lookup("ejb:/ProjectName//NameOfBean!de." + "mypath.sessionbean.stateless.NameOfBeanInterface");
Isnt that possible in OpenEJB? Do I have to change every lookup call in every bean to have a local test with OpenEJB? That wouldn't be really effective and time-saving.
Problem solved!
The strukture of the lookup is {deploymentId}{interfaceType.annotationName}. Therefore in my case it must be
initialContext.lookup("NameOfBeanLocal");
or
initialContext.lookup("NameOfBeanRemote");
depending on the type of the interface.
To get the problem with JBoss solved you can switch from default lookup
new InitialContext().lookup("ejb:/ProjectName//NameOfBean!de." + "mypath.sessionbean.stateless.NameOfBeanInterface");
to something more flexible like Dependcy-Lookup or Dependency-Injection and use the #EJB annotation. Both ways are supportet by JBoss and OpenEJB.

bug in aspnet_compiler?

I have a solution with several web projects.
I have built each project into its own folder (there's about 10 projects):
/build/projA
/build/projB
/build/projC
If I call
aspnet_compiler -v / -p \"build/#{proj}\" merged/#{proj}
on each one in turn, everything is fine.
If I make all 10 calls to aspnet_compiler in parallel, I get assembly loading errors, saying the referenced assemblies are in use.
Is this a bug? Why would it be in use? It shouldn't be.
The assemblies that cant be loaded are in multiple projects, but each one has its own copy in its bin folder.
Update: it seems to occur (for some) of the assemblies that are references of references. Those loaded with complete binding information seem to work.
Here's a dump from one of the failed loadings from fuslogvw
The operation failed.
Bind result: hr = 0x80070020. The process cannot access the file because it is being used by another process.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = andrew.bullock
LOG: DisplayName = Yahoo.Yui.Compressor
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Yahoo.Yui.Compressor | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///E:/build/ProjA/
LOG: Initial PrivatePath = E:\build\ProjA\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\src_projects_proja\061ad2e7
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\src_projects_proja\061ad2e7
LOG: AppName = 627cc9a9
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\build\ProjA\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/src_projects_proja/061ad2e7/627cc9a9/Yahoo.Yui.Compressor.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/src_projects_proja/061ad2e7/627cc9a9/Yahoo.Yui.Compressor/Yahoo.Yui.Compressor.DLL.
LOG: Attempting download of new URL file:///E:/build/ProjA/bin/Yahoo.Yui.Compressor.DLL.
LOG: Assembly download was successful. Attempting setup of file: E:\build\ProjA\bin\Yahoo.Yui.Compressor.dll
LOG: Entering download cache setup phase.
ERR: Error extracting manifest import from file (hr = 0x80070020).
ERR: Setup failed with hr = 0x80070020.
ERR: Failed to complete setup of assembly (hr = 0x80070020). Probing terminated.
If you call the ClientBuildManager directly, outside of aspnet_compiler there doesn't seem to be a problem, no idea why.
var parameter = new ClientBuildManagerParameter
{
PrecompilationFlags = PrecompilationFlags.ForceDebug
};
var client = new ClientBuildManager("/", src, dest, parameter);
client.PrecompileApplication();

Resources