Create jar file that can be executed on any machine - manifest

I have simple java app that prints `hello world!' on console. It is packed in app.jar.
Jar structure:
main/Hello.class - my main class with singe println method
META-INF/MANIFEST.MF
Manifest file contains following:
Manifest-Version: 1.0
Main-Class: main.Hello
Everything goes fine.
But when you have a dependency than troubles begin. I'm not sure but think in this case you have to put all libs to jar file. If I put them in META-INF/lib I must specify "Class-Path" in manifest. How "Class-Path" will look?
P.S There are some resembling questions but I haven't found appropriate answer.

I tend to use an ANT build script to package my application and all necessary jar files. I find this makes life much easier once you've got it working properly.
build.xml file looks something like:
<project default="create_run_jar" name="Create Runnable Jar for MyProject">
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="my-runnable-jar.jar">
<manifest>
<attribute name="Main-Class" value="my.MainClass"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="E:/path/to/my/project/bin"/>
<fileset dir="E:/path/to/my/project/classes"/>
<zipfileset src="E:/path/to/library/some-library.jar"/>
</jar>
</target>
</project>
Note that if you use Eclipse, you can simplly do File / Export... / Runnable jar file and it will do everything for you (including generating the ANT build.xml).

You don't have to specify anything special if you unpack the libraries and integrate them into your project. If you do this, you should have a "main" folder, and if you have org.apache.foo as an external library, you'll also have an "org" folder at the top level.

Related

Extend OTB slingshot search Webscript Alfresco 5.0 C

I want to add a csv response template to the default slingshot/search? web script which is inside in a jar (Alfresco remote api).
Already l have an ant script which build a jar inside Alfresco/tomcat/shared/lib
Inside this jar l have define an extension xml file config/alfresco/site-data/extensions/extension-modules.xml
<extension>
<modules>
<module>
<id>Custom DocumentList Widget</id>
<description>Extend Alfresco Search</description>
<customizations>
<customization>
<targetPackageRoot>org.alfresco.slingshot.search
</targetPackageRoot>
<sourcePackageRoot>webscripts.search</sourcePackageRoot>
</customization>
</customizations>
</module>
</modules>
</extension>
Also lnside config/webscripts/search l have the search.get.csv.ftl file but I never get the csv response. Is this the best way to modify/extend the default web script ?
No this isn't the best way to extend this in your case.
Normally it is, but in your case just use the default override mechanism of Alfresco.
So just place your addition in org/alfresco/slingshot/search, cause Alfresco doesn't has a csv.ftl file, so it will be available.
The extension module is uses to extend/change the default get.js & get.html.ftl file, so I'm not sure if it will accept any addition if you don't specify the one of the above files.

Is it possible to access a html outside of webapp?

I have a process to generate html file dynamically, but i dont want to place those html files under the webapp, because if the project are re-deployed, I have to deal with the existing html files(copy out and copy in).
So I'm just wondering if I can place the html files outside of the webapp.
If not, is there any other proper way to meet the requriement?
I'm using tomcat.
Appropriate your help.
Create below dir if not exist:
${CATALINA_HOME}/conf/Catalina/localhost
Create a xml file "article.xml", place the xml under the above path as follows.
${CATALINA_HOME}/conf/Catalina/localhost/article.xml
Add below content to the xml.
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/article" docBase="C:/apps/blog/article" debug="0"
reloadable="true" privileged="true">
</Context>
Start tomcat.
If there's aa.html under the C:/apps/blog/article, use http://localhost:8080/article/aa.html to access the html.
NOTE:
1. Tomcat will take the xml as an web application, and load the resource configed in the xml.
2. No need to create WEB-INF and META-INF for the external folder(C:/apps/blog/article here).

Gradle replace token in a file during build process

I have a web application and I use gradle to build it. In one of the xml files in WEB-INF folder (src/main/webapp/WEB-INF/my.xml) I have a piece of file that needs replacing.
<system-properties>
<property name="clientId" value="#clientId#" />
</system-properties>
When I try to replace the token with some value using:
processResources{
filter(ReplaceTokens, tokens:['clientId': 'test'])
}
Than when I run gradle build the token in the output file (./build/exploded-app/WEB-INF/my.xml) is not replaced. I was wondering which is the correct way to do this?
The problem is that you are configuring the wrong task. processResources only copies files from src/main/resources (or whatever else you define in the main sourceSet as resource), while it is task war which copies / zips your my.xml.
war {
filter(ReplaceTokens, tokens:['clientId': 'test'])
}

Converting folder of XML files to folder of HTML files

I have a folder of several hundred XML files that I would like to convert into a folder of HTML files. I've created an XSLT that works in w3schools.com's XSLT tester, but I'm not sure how to apply that stylesheet across hundreds of XML documents. My XML looks like this (and the only nodes I'm interested in are title, author, and lyrics):
<?xml version='1.0' encoding='utf-8'?>
<song xmlns="http://openlyrics.info/namespace/2009/song" version="0.8" createdIn="OpenLP 2.0.1" modifiedIn="OpenLP 2.0.1" modifiedDate="2012-03-14T02:21:52">
<properties>
<titles>
<title>Amazing Grace</title>
</titles>
<authors>
<author>John Newton</author>
</authors>
</properties>
<lyrics>
<verse name="v1">
<lines>Amazing grace, how sweet the sound<br/>That saved a wretch like me<br/>I once was lost, but now am found<br/>Was blind but now I see</lines>
</verse>
A couple questions about this:
1) Might it be better to use XQuery since I'm only interested in extracting a few lines per XML file?
2) Regardless of XSLT/XQuery, how can I implement a solution that converts a folder of XML files (without manually editing each one to call upon the XSL stylesheet)? I'm running OS X 10.8.4.
Thanks in advance.
Just write your own shell script using the xsltproc command. This is what I used successfully for XSLT batch processing.
Or just open a shell, cd to the folder with the XML files and then enter the following two commands:
mkdir results
xsltproc -o results/ path/to/stylesheet.xslt *.xml
I think XQuery would be more convenient if you had all of your XML in a database, but on the filesystem XSLT may be simpler.
I would just use Saxon-PE, and invoke it from a shell script. You could also use Automator.

how to inject ant build time to an html page

Anyone know how to inject an ant build date time stamp into an html page?
When you refer ant, I assume you're on Java.
You can use tstamp task and echo to a property file. This property file can be bundled into the jar so that the application can read the property and display the value as required.
Ex:
<target name="build.timestamp">
<tstamp>
<format property="build.timestamp" pattern="yyyy.MM.dd-hh.mm.ss" locale="en,UK"/>
</tstamp>
<echo message="tstamp=${build.timestamp}" file="build-timestamp.properties"/>
</target>
This will create a build-timestamp.properties in current ant directory.
Jar it up as a regular resource file along with application classes so that it becomes available at app run time.