relative path of resource files? - maven

when i deploy a project to servicemix i do a "mvn install" then inside servicemix i simply do: "osgi:install -s mvn:my.package.x/proj".
now when i want to reference a file inside the package i get a "file not found exception"
in my .m2 directory the package structure inside the jar looks like this (if i unpack to look):
servicemixTest-0.0.1-SNAPSHOT
--my
----package
------processingFile.class
--resources
------xsl
---------fileForTransformation.xsl
now in the processing Class i need to reference the xsl file with camel like this:
.from(url) .to("xslt:file:./data/xsl/transformation.xsl") .process()
i already tried:
../../
./
nothing ("xslt:file:data/xsl/tr...")
my question is now: "how do I find resource files inside a deployed container?"

If your XSL file is packaged in the JAR file, you don't need the file: part in the URI. You can just refer to the location inside the JAR directly, like this:
from("direct:start").to("xsl:resources/xsl/fileForTransformation.xsl").process()

Related

How can I submit an Apache Storm topology to a Storm cluster?

I'm following this tutorial: https://learn.microsoft.com/en-us/azure/hdinsight/storm/apache-storm-develop-java-topology
What I've done so far is
maven setting
vi *.java files (in src/main/java/com/microsoft/example directory)
RandomSentenceSpout.java
SplitSentence.java
WordCount.java
WordCountTopology.java
mvn compile
jar cf storm.jar *.class (in target/classes/com/microsoft/example directory)
RandomSentenceSpout.class SplitSentence.class WordCount.class WordCountTopology.class
The above 4 files were used to make storm.jar file
Then, I tried
storm jar ./storm.jar com.microsoft.example.WordCountTopology WordCountTopology
and
storm jar ./storm.jar WordCountTopology
, but both of these failed, saying:
Error: Could not find or load main class com.microsoft.example.WordCountTopology
or
Error: Could not find or load main class WordCountTopology
According to a document, it says
Syntax: storm jar topology-jar-path class ...
Runs the main method of class with the specified arguments. The storm
jars and configs in ~/.storm are put on the classpath. The process is
configured so that StormSubmitter will upload the jar at
topology-jar-path when the topology is submitted.
I cannot find where to fix.
How can I resolve this?
I think your jar file does not contain class WordCountTopology. You can check it with jar tf storm.jar | grep WordCountTopology.
Looks like your jar does not contain a Manifest file which keeps information about the main class.
Try including the Manifest file or you can run the below java command to include the Manifest file
Hope this works!
jar cvfe storm.jar mainClassNameWithoutDotClassExtn *.class

Copy to directory outside of project directory using Gradle 4.0.2

I have a gradle build which generates war file. I want to copy war file to my application servers' dropins directory which is somewhere outside of project directory. I have following copy task to do this.
task copyWarToDropins(type: Copy,dependsOn:[war]) {
from './build/libs/bds-service-token-1.0-SNAPSHOT.war'
into file('/apps/dropins') // want to copy to 'C:/apps/dropins' directory
rename { fileName -> 'bds-service-token.war' }
}
build.dependsOn copyWarToDropin
It evaluates /apps/dropins relative project directory and does copy there. I have tried many ways I can think of but could not make it copy to C:/apps/dropins directory.
Can someone please help?
First, please note that using into file(...) is redundant, as each call to into(...) will be evaluated via Project.file(...) anyhow.
As you can read in the documentation , file(...) handles strings in the following way:
A CharSequence, including String or GString. Interpreted relative to the project directory. A string that starts with file: is treated as a file URL.
So, one way to solve your problem could be using an absolute file URL.
However, if you continue to read the documentation, you will see that Java File objects are supported. So you could simply create such an object:
into new File('C:/your/absolute/path')

How do I copy a file into my WAR's META-INF directory?

I’m using Gradle 2.7. I would like to copy an environment-specific file (context.xml) into my WAR’s META-INF directory (which is at the same level as WEB-INF). I have this task set up in my build.gradle file
// Copy context.xml into the appropropriate directory.
war {
def env = project.hasProperty('env') ? project.env : 'dev'
from("${project.rootDir}/src/main/environment/$env") {
include('context.xml')
into('META-INF')
}
}
However, when I run “gradle build”, nothing gets copied. I have verified the file exists. What else do I need to do to get this file to copy properly?
It seems that your script is configured correctly. It's stupid question (it should've failed at the very beginning) but have you applied war plugin?
Here you have a demo to compare the configurations.
Run:
jar -tvf <lib>.war
to verify if war contains appropriate file.

How can I make gradle include *.ftl files in war file

I have the following structure:
src/main/java/com/company/SomeJavaFile.java
src/main/java/com/company/template_file.ftl
When I create a build using gradle, the *.ftl files dont get included in the war file.
How can I make gradle include them in the war file?
Another solution would be to put your *.ftl files into src/main/resources directory instead.
Ok, found it. You simply add the following line to your build file:
gradle.build file (add the following line):
sourceSets.main.resources.srcDir 'src/main/java'
Got the answer from the following discussion thread:
http://gradle.1045684.n5.nabble.com/Copy-non-java-files-into-the-target-directory-td1432058.html
Why not put them in src/main/webapp where, if you used them, *.jsp files would go?

How to add META-INF/context.xml in Warbler

How can I add META-INF/context.xml into the war? I didn't find any config entry in config/warble.rb.
Unfortunately Nick's method doesn't work. The file is actually copied to WEB-INF/META-INF/context.xml.
I finally figure out a way to copy context.xml to META-INF:
create META-INF/context.xml under your rails app root folder
uncomment and change the following line in config/warble.rb
config.public_html = FileList["public/**/*", "doc/**/*", "META-INF/context.xml" ]
Basically treat META-INF as public_html, and it will be copied to webapps/youapp/META-INF.
You'll have to add one yourself. You can either create a META-INF/context.xml directory and file in your project and add META-INF to config.dirs in config/warble.rb or you can add a "pathmap" to rename the context.xml file into the META-INF directory in the war file.
config.pathmaps.application += ["%{context.xml,META-INF/context.xml}p"]
A better way of tackling this might be to use the following in your warble.rb file.
config.script_files << 'path_to_file/context.xml'
See documentation towards bottom of https://github.com/jruby/warbler/blob/master/lib/warbler/config.rb
# These file will be placed in the META-INF directory of the jar or war that warbler
# produces. They are primarily used as launchers by the runnable feature.
attr_accessor :script_files

Resources