add permissions attribute in manifest third party jars using maven - java

How can we add additional parameters to manifest file using Maven to third party jars. After Java 7_25 version the Java web start requires codebase and permissions to be add in all downloading jar files. I want to insert them jar singing time.
Please let me know if you need any information. Thanks in advance.

i made a little ant script (this is an extract, in fact it also excludes some crypto file).
just set directory property value to a directory that contains jars to be updated and launch the target "give-permissions".
it should be easy to use with maven-ant:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="project">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property name="directory" value="WebContent/jnlpApplication" />
<target name="give-permissions">
<foreach target="_re-jar" param="currentFile" parallel="false">
<path>
<fileset dir="${directory}" casesensitive="yes">
<include name="**/*.jar" />
</fileset>
</path>
</foreach>
<move todir="${directory}" overwrite="true">
<fileset dir="${directory}.tmp" casesensitive="yes">
<include name="**/*.jar" />
</fileset>
</move>
<delete dir="${directory}.tmp" />
</target>
<target name="_re-jar">
<basename property="filename" file="${currentFile}" />
<jar destfile="${directory}.tmp/${filename}">
<zipfileset src="${currentFile}">
<exclude name="META-INF/**.RSA" />
<exclude name="META-INF/**.SF" />
</zipfileset>
<manifest>
<attribute name="Permissions" value="all-permissions" />
<attribute name="Codebase" value="*" />
<attribute name="Application-Name" value="jnlpApplicationName" />
</manifest>
</jar>
</target>
</project>

Related

Authentication Provider does not appear in the list of Authenticators in WebLogic Server Version: 12.1.3.0.0

I've just created an Authentication Provider for WebLogic Server Version: 12.1.3.0.0, put the jar in the lib of the domain, but does not appear in the List of Providers to select
<?xml version="1.0"?>
<!DOCTYPE MBeanType SYSTEM "commo.dtd">
<!-- MBean Definition File (MDF) for the MMR WS Authenticator See documentation at: http://docs.oracle.com/cd/E13212_01/wles/docs42/dvspisec/mdf_ref.html Since it is for an identity asserter, it must extend the weblogic.management.security.authentication.IdentityAsserter mbean. The Name and DisplayName must be the same. They specify the name that will appear on the console for this provider. Set the PeristPolicy to "OnUpdate" so that if an attribute value is changed, the new value is written to disk immediately. See the "Developing Security Services" manual for more info. Note that since this is an xml document, you can't use double quotes directly. Instead you need to use " Note that setting "Writeable" to "false" on an attribute makes the attribute read-only. The default is read-write. -->
-<MBeanType PersistPolicy="OnUpdate" Extends="weblogic.management.security.authentication.Authenticator" Package="fr.telecom.security.authentication.provider.mbean" Name="MMRWSAuthenticator">
<!-- You must set the value of the ProviderClassName attribute (inherited from the weblogic.management.security.Provider mbean) to the name of the java class you wrote that implements the weblogic.security.spi.AuthenticationProvider interface. You can think of the provider's mbean as the factory for your provider's runtime implementation. -->
<MBeanAttribute Name="ProviderClassName" Default=""fr.telecom.security.authentication.provider.MMRWSAuthenticationProviderImpl"" Preprocessor="weblogic.management.configuration.LegalHelper.checkClassName(value)" Writeable="false" Type="java.lang.String"/>
<!-- You must set the value of the Description attribute (inherited from the weblogic.management.security.Provider mbean) to a brief description of your provider. It is displayed in the console. -->
<MBeanAttribute Name="Description" Default=""MMR WS Authenticator"" Writeable="false" Type="java.lang.String"/>
<!-- You must set the value of the Version attribute (inherited from the weblogic.management.security.Provider mbean) to your provider's version. There is no required format. -->
<MBeanAttribute Name="Version" Default=""1.0"" Writeable="false" Type="java.lang.String"/>
</MBeanType>
This is my build.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!--
This project is not entirely handled by Maven, so be careful when generating the artifact, and use Ant with its default target.
-->
<project name="devices-ws-authentication-provider" default="all" basedir=".">
<echo>
Remember to execute the command below before doing an Ant:
%MW_HOME%\wlserver\server\bin\setWLSEnv.cmd
</echo>
<property name="src-java" value="src/main/java" />
<property name="mbean" value="src/mbean" />
<target name="all" depends="build" />
<target name="build" depends="clean,build.mdf,build.mjf" />
<target name="clean">
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${mbean}" includes="**/*"/>
</delete>
<delete file="target/devices-ws-authentication-provider-1.0.0-SNAPSHOT.jar" failonerror="false" />
<mkdir dir="target" />
<echo message="Clean finish" />
</target>
<!-- helper to build an MDF (mbean definition file) -->
<target name="build.mdf">
<java dir="${basedir}" fork="false" classname="weblogic.management.commo.WebLogicMBeanMaker">
<arg line="-files ${mbean}" />
<arg value="-createStubs" />
<arg line="-MDF src/main/resources/TntWSAuthenticator.xml" />
</java>
<echo message="Created Supporting Classes" />
<move todir="${src-java}/fr/telecom/security/authentication/provider/mbean" file="${mbean}/TntWSAuthenticatorImpl.java" />
<move todir="${src-java}/fr/telecom/security/authentication/provider/mbean" file="${mbean}//fr/telecom/security/authentication/provider/mbean/TntWSAuthenticatorMBean.java" />
</target>
<target name="build.mjf">
<mkdir dir="${mbean}" />
<copy todir="${mbean}">
<fileset dir="src/main/java">
<include name="**/*" />
</fileset>
<fileset dir="src/main/resources">
<include name="**/*" />
</fileset>
</copy>
<java dir="${basedir}" fork="false" classname="weblogic.management.commo.WebLogicMBeanMaker">
<arg line="-MJF target/devices-ws-authentication-provider-1.0.0-SNAPSHOT.jar" />
<arg line="-files ${mbean}" />
</java>
<echo message="Mbean JAR created." />
<!-- Do a small cleanup after building the JAR, in order to not have duplicated sources / classes in source paths -->
<!--
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${mbean}" includes="fr/telecom/security/authentication/provider/*.java" />
<fileset dir="${mbean}" includes="fr/telecom/domain/**/*.java" />
<fileset dir="${mbean}" includes="commo.dtd" />
<fileset dir="${mbean}" includes="rebel.xml" />
<fileset dir="${mbean}" includes="TntWSAuthenticator.xml" />
</delete>
-->
</target>
<target name="install" depends="build">
<copy todir="${user.home}/devices/lib" file="target/devices-ws-authentication-provider-1.0.0-SNAPSHOT.jar" />
</target>
</project>
opening the generated ear I see that there is some missing folders and files, like
/schemacom_bea_xml/element
/schemacom_bea_xml/namespace
/schemacom_bea_xml/system
/schemacom_bea_xml/type
/weblogic/
WLS providers is a nightmare, I have already developed two and now I am using Spring Security :) for the shake of simplicity and portability.
Well, I read your build.xml and it result strange for me, but the most obvious thing I see is that you lack the following argument:
<arg line="-targetNameSpace your.namespace.here" />
inside WebLogicMBeanMake ant rule. Try it, but if it does not work I will recommend you to redo. I can provide you some samples.
Edit
In response to your comment, I will include here a sample that I have already working in a real project.
This is a build.xml file to be run with and. To run this sample it is required to have WLS 12c installed. Before run ant buildAndDeploy you have to run ${WLS_HOME}/server/bin/setWLSEnv.sh script to prepare environment.
You have to adapt global properties at the beginning of the file.
<project name="ldap-db-provider" default="buildAndDeploy" basedir=".">
<description>Custom Authentication Provider Build</description>
<!-- global properties -->
<property name="base.dir" location="." />
<property name="bea.home" location="/opt/weblogic/Oracle/Middleware/Oracle_Home" />
<property name="mbean.maker" location="${bea.home}/wlserver/modules/com.bea.core.mbean.maker_2.1.0.0.jar" />
<property name="wls.home" value="${bea.home}/wlserver" />
<property name="wls.lib.dir" value="${wls.home}/server/lib" />
<property name="mbeantypes.dir" value="${wls.lib.dir}/mbeantypes" />
<property name="jar.file.name" value="your-name-for-the-provider-package.jar" />
<property name="src.dir" value="${base.dir}/src" />
<property name="provider.src.dir" value="${src.dir}/es" />
<property name="build.dir" value="${base.dir}/build" />
<property name="targetNamespace" value="your.target.name.space"/>
<property name="mbean.impl.name" value="YouBeanName" />
<property name="mbean.package" value="your/mbean/pacakage/name" />
<target name="updateSources">
<copy todir="${src.dir}/${mbean.package}" flatten="true">
<fileset dir="${build.dir}">
<include name="${mbean.impl.name}Impl.java" />
</fileset>
</copy>
<copy todir="${src.dir}/${mbean.package}" flatten="true">
<fileset dir="${build.dir}/${mbean.package}">
<include name="**/*.java" />
</fileset>
</copy>
</target>
<target name="buildAndDeploy" depends="clean">
<mkdir dir="${build.dir}" />
<copy todir="${build.dir}" flatten="true">
<fileset dir="${wls.lib.dir}">
<include name="commo.dtd" />
</fileset>
</copy>
<copy todir="${build.dir}" flatten="true">
<fileset dir="${provider.src.dir}">
<include name="**/*.xml" />
<include name="**/*.java" />
</fileset>
</copy>
<java
classname="weblogic.management.commo.WebLogicMBeanMaker"
fork="true" failonerror="true">
<!-- <classpath refid="build.path"/> -->
<arg line="-files ${build.dir}" />
<arg value="-createStubs" />
<arg line="-MDF ${build.dir}/${mbean.impl.name}-Mbean.xml" />
</java>
<echo message="Created Supporting Classes" />
<java
classname="weblogic.management.commo.WebLogicMBeanMaker"
fork="true" failonerror="true">
<!-- <classpath refid="build.path"/> -->
<arg line="-MJF ${build.dir}/${jar.file.name}" />
<arg line="-targetNameSpace ${targetNamespace}" />
<arg line="-files ${build.dir}" />
</java>
<echo message="Created Mbean Jar" />
<!-- Deploy the sample security providers -->
<copy todir="${mbeantypes.dir}" flatten="true">
<fileset dir="${build.dir}">
<include name="${jar.file.name}" />
</fileset>
</copy>
</target>
<target name="clean">
<delete quiet="true" dir="${build.dir}" />
<delete>
<fileset dir="${src.dir}/${mbean.package}" includes="**/*.java" />
</delete>
<delete quiet="true" file="${mbeantypes.dir}/${jar.file.name}" />
</target>
</project>
Hope it helps!

Excluding files from ant build in javadocs

So here i am with yet another javadoc question: Here is my stuff
[code]
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false">
</javac>
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
<jar destfile="${dist.dir}\driver.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="driver.Driver" />
</manifest>
</jar>
<description>run the program</description>
<java jar="${dist.dir}/driver.jar" fork="true">
<!-- if you needed arguments -->
<!--
<arg value="${args0}" />
<arg value="${args1}" />
-->
</java>
<description>Main target</description>
now my src folder has files known as input1.txt, input2.txt, input3.txt, and when im generating docs, i get this error:
[javadoc] javadoc: error - Illegal package name: blablabla/input1.txt
I tried using the excludes command but it says javadoc doesn't support that. Is there a way i can exclude files with a .txt ending from being trying to made javadocs off of?
I am pretty new to ant so any help is appreciated :)
You can use the excludes attribute in <fileset> or several <exclude name="..." /> nested in <fileset> to exclude certain files from the fileset that will be sent to javadoc.

precompile jsps into classes for Jetty8 using ant

We are using jspc ant task to pre-compile JSP files into classes/(then package into war)
Now we are switching to Jetty 8. According to the doc, there exists a maven plugin to do this. Do we have ant task to do the same?
Its best if you use the JSP libs that comes with the jetty distribution.
Here's an example, using jetty-distribution-8.1.5.v20120716
<?xml version="1.0" ?>
<project name="AntExample1" default="war">
<property name="jetty.home" value="${user.home}/code/intalio/distros/jetty-distribution-8.1.5.v20120716" />
<path id="compile.jspc">
<fileset dir="${jetty.home}">
<include name="lib/servlet-api-*.jar" />
<include name="lib/jsp/*.jar" />
</fileset>
</path>
<path id="compile.classpath">
<fileset dir="WebContent/WEB-INF/lib">
<include name="*.jar" />
</fileset>
<path refid="compile.jspc" />
</path>
<target name="jspc" depends="compile">
<taskdef classname="org.apache.jasper.JspC" name="jasper2" classpathref="compile.jspc" />
<jasper2 validateXml="false"
uriroot="WebContent"
addWebXmlMappings="true"
webXmlFragment="WebContent/WEB-INF/generated_web.xml"
compilerSourceVM="1.6"
compilerTargetVM="1.6"
outputDir="build/gen-src"
verbose="9" />
</target>
<target name="init">
<mkdir dir="build/classes" />
<mkdir dir="build/gen-src" />
<mkdir dir="dist" />
<copy todir="build/gen-src">
<fileset dir="src" includes="**/*.java" />
</copy>
</target>
<target name="compile" depends="init">
<javac destdir="build/classes" debug="true" srcdir="build/gen-src">
<classpath refid="compile.classpath" />
</javac>
</target>
<target name="war" depends="jspc">
<war destfile="dist/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<classes dir="build/classes" />
</war>
</target>
<target name="clean">
<delete dir="dist" />
<delete dir="build" />
</target>
</project>
Update: April 8, 2013
Pushed an example project with this build to github.
https://github.com/jetty-project/jetty-example-jspc-ant
Jasper has jspc; the linked page has ant code for calling it.
From your first sentence you are apparently already using an ant task to pre-compile the jsp files...so using jetty-8 doesn't mean you have to change that process at all, you will still just pre-compile as you have been, building your war file as you have been and then just deploy into jetty-8. You will need to add jsp to the OPTIONS in the start.ini to get the jsp engine into the server classloader.

How to build a jar using an own MANIFEST.MF in Eclipse

I have a custom MANIFEST.MF in my java-project in Eclipse.
When exporting the project to a jar, I choose
Use existing manifest from workspace
Extracting the .jar shows that eclipse generated its own manifest.
My manifest:
Manifest-Version: 1.0
Main-Class: de.somehow.tagPDF.Main
Class-Path: lib/iText-5.0.2.jar;lib/jxl.jar;lib/jai_codec.jar;lib/jai_core.jar
How can I fix this?
You can make use of a build.xml to build the jar file for you.
Then you just run the build.xml as a Ant task.
See
If you want the build.xml to run automatically every time you build your Eclipse project, you can add it to the Builders list.
See
Below is a sample build.xml where a custom manifest is used:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="Example" default="run_build">
<property name="guiJar" value="../../Library/<jar-name>.jar"></property>
<target name="run_build" depends="delete_old_jar,create_dirs,create_manifest,copy_all_class_files,create_jar,delete_temp_dirs">
</target>
<target name="delete_old_jar">
<delete file="${guiJar}">
</delete>
</target>
<target name="create_dirs">
<mkdir dir="jar_temp" />
<mkdir dir="jar_temp/META-INF" />
</target>
<target name="delete_temp_dirs">
<delete dir="jar_temp">
</delete>
</target>
<target name="create_manifest">
<manifest file="jar_temp/META-INF/MANIFEST.MF">
<attribute name="Manifest-Version" value="1.0" />
<attribute name="Version" value="1.0.0" />
<attribute name="Company" value="Value" />
<attribute name="Project" value="Value" />
<attribute name="Java-Version" value="${java.version}" />
<attribute name="Class-Path" value="test.jar" />
<attribute name="Main-Class" value="com.Main" />
</manifest>
</target>
<target name="create_jar">
<jar destfile="${guiJar}" manifest="jar_temp/META-INF/MANIFEST.MF" basedir="jar_temp">
</jar>
</target>
<target name="copy_all_class_files">
<copy todir="jar_temp">
<fileset dir="classes">
<include name="*/**" />
</fileset>
</copy>
</target>
</project>
In eclipse 3.6.1.
Rigth click on your compiled project -> Export
Next you should choose Java - JAR File from the tree
In new form appeared after you select options don't click finish but 'Next'.
Third form will be 'JAR Manifest Specification' and there you can choose your manifest file instead of eclipse generated one.

Java applet, add jar files to the manifest file

I am doing some thing obvious wrong. I have a simple applet which needs to upload files to server. I have written an ant script to build the jar file. However, the manifest.mf has class-path split into multiple lines.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Class-Path: lib/commons-codec-1.3.jar lib/commons-httpclien
t-3.1.jar lib/commons-logging-1.0.4.jar lib/plu
gin.jar
Created-By: 14.3-b01-101 (Apple Inc.)
My build.xml is :
<project name="ScreenShot" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src" />
<property name="build" location="build" />
<property name="dist" location="dist" />
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
</target>
<target name="compile" depends="init" description="compile the source ">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath>
<pathelement path="${classpath}" />
<pathelement path="lib/commons-codec-1.3.jar:lib/commons-httpclient-3.1.jar:lib/plugin.jar" />
</classpath>
</javac>
</target>
<target name="dist" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}" />
<copy todir="${build}/lib">
<fileset dir="lib/" />
</copy>
<path id="libs.project">
<!-- lib.home contains all jar files, in several subdirectories -->
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
<manifestclasspath property="jar.classpath" maxParentLevels="1" jarfile="build/ScreenShot.jar">
<classpath refid="libs.project" />
</manifestclasspath>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="/Users/firemonk/red5/webapps/whiteboard/ScreenShot.jar" basedir="${build}">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}" />
<delete dir="${dist}" />
</target>
</project>
Check the value of ${jar.classpath}. It seems its value itself is in multiple lines.
Does it not work? It's a bit odd that there are big spaces between each classpath entry but it looks valid.
The manifest specification states that lines must be no longer than 72 bytes and that longer lines should be split and continued on the next line with a leading space.

Categories