Error using jaxb external bindings customization - java

I use the wsdlc tool (weblogic 10.3.1) to generate classes from wsdl.
I have the following external jaxb bindings customization file:
<jaxb:bindings
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
schemaLocation="web/WEB-INF/....xsd"
version="2.1">
<jaxb:bindings node="/xs:schema">
<jaxb:globalBindings>
<xjc:superClass name="my.MySuperClass" />
</jaxb:globalBindings>
</jaxb:bindings>
</jaxb:bindings>
The error message on complilation is: cannot find symbol my.MySuperClass.
And from javac: "package my does not exist". The classpath = everything I include via <pathelement location= etc. and 60 lines from eclipse plugins. The problem lies in the javac command that wsdlc initiates. The classpath of this command is correct (hard coded paths e.g.) but still "package ... does not exist".
The usage of wsdlc from ant is like so:
<path id="class.path">
<pathelement path="${java.class.path}" />
<pathelement location="... hard coded path on disk to a jar" />
</path>
<target name="generate-ws-from-wsdl">
<wsdlc failOnError="true"
srcWsdl="${basedir}/web/WEB-INF/ps.wsdl"
destImplDir="${basedir}/src"
destJwsDir="${basedir}/web/WEB-INF/lib"
srcPortName="PsPort"
type="JAXWS">
<binding file="jaxb-bindings.xml" />
<classpath refid="class.path" />
</wsdlc>
</target>

my.SuperClass has to exist already, wsdlc won't generate it for you. When it comes to compiling the generated code (which is where I assume is what is failing here), it's because javac can't find my.SuperClass in its classpath.

Please provide the excerpt of the build.xml showing how you use use the wsdlc.
According to the documentation:
In addition to the WebLogic-specific
wsdlc attributes, you can also define
the following standard javac
attributes; see the Ant documentation
for additional information about each
attribute:
bootclasspath
bootClasspathRef
classpath
[...]
You can also use the following
standard Ant child elements with the
wsdlc Ant task:
<FileSet>
<SourcePath>
<Classpath>
Did you specify the classpath to include my.SuperClass?

I didn't jar my classes properly, I thought I could use WinZip to quickly add some classes to a jar, but the 'path' in WinZip was not equal to the package name in java. It took me a while but I learned something about classpaths.

Related

Ant javac task not compiling. Its 'srcdir' parameter not behaving as documented. Is this a bug?

I have written the Ant script pasted below. It uses the javac task. The Apache documentation states that scrdir parameter is used to point to the source (.java) files. But it also explains that the javac task can use patternsets.
I believe there may be a bug in the javac task or at least, perhaps a poor implementation of the javac Ant task.
In my code, the compile target fails because the source files cannot be found. Can anyone please explain why?
Background:
Directory structure of my project is as follows:
My ant scripts are in the ant directory.
Source files are inside wm-adapter/src
<?xml version="1.0" encoding="UTF-8"?>
<project name="wm-adapter" default="dev" basedir=".">
<property file="Build.properties"/>
<property name="build.compiler" value="javac1.5"/>
<target name="compile" depends="prepare">
<!-- Define required FileSets and PatternSets... -->
<patternset id="patternset.wm.adapter.sources">
<include name="${source.dir}/*.java"/>
<exclude name=""/>
</patternset>
<fileset id="fileset.wm.adapter.sources" dir="${proj.dir}">
<patternset refid="patternset.wm.adapter.sources"/>
</fileset>
<!-- Compile... -->
<javac srcdir="${basedir}"
destdir="${classes.dir}"
classpath="${compile.classpath}"
debug="${javac.debug}"
verbose="true"
fork="true"
source="1.5"
target="1.5">
<patternset refid="patternset.wm.adapter.sources"/>
</javac>
<echo message=" Compilation completed successfully!"/>
</target>
Here is a snippet from the properties file:
# DEFINE DIRECTORY STRUCTURE...
proj.dir=../wm-adapter
source.dir=${proj.dir}/src
build.dir=${proj.dir}/build
classes.dir=${build.dir}/classes
dist.dir=${proj.dir}/dist
lib.dir=../lib
docs.dir=${proj.dir}/documentation
resources.dir=${proj.dir}/www
config.dir=${proj.dir}/config
# DECLARE ANY OTHER WORKING DIRECTORIES...
tmp.jar.dir=C:\\Temp
tmp.app.dir=${tmp.jar.dir}/FATCA_WM_Adapter
# Name the jar file...
jar.file=FATCA_WM_Adapter.jar
# IMPORT EXTERNAL JARS INTO OUR CLASSPATH...
compile.classpath=${g11nutils.jar};${javax.ejb_3.0.jar};${middleware_UTILS.jar};${wmbrokerclient.jar};${classes.dir}
compile.classpath=${classes.dir};${lib.dir}
basedir has been defined as '.'
I know how to make it work: The target will compile if:
I make changes to the patternset as shown below:
<patternset id="patternset.wm.adapter.sources">
<include name="src/*.java"/>
<exclude name=""/>
</patternset>
Within the javac task I ammend srcdir to:
srcdir="${proj.dir}"
But this is a fix! Why do my original settings not work?
basedir here is equal to your 'ant' subdir, which is probably why it doesn't work. Perhaps you want <project basedir=".."> at the top.

Ant with IntelliJ IDEA encoding problems

I'm using IntelliJ IDEA with Ant on Windows 10 to compile & run my project using build.xml
All my files (even build.xml) are coded in UTF-8
I'm using UTF-8 in XML specification & javac command
<?xml version="1.0" encoding="UTF-8"?>
<javac target="1.8" srcdir="${test}" destdir="${build}" encoding="UTF-8" includeantruntime="false">
I have set UTF-8 as default encoding in IDE
Still not working. It writes diamonds with question marks when there are some diacritics on output.
May it be something related to that I'm making JAR file which is then executed?
The solution is to add jvm argument within build.xml file.
Example:
<target name="execute" description="Launch an app" depends="jar">
<java jar="${dist}/${jarname}" dir="${dist}" fork="true">
<jvmarg value="-Dfile.encoding=UTF-8"/>
</java>
</target>

Ant taskdef - requires both classpath and -lib parameter?

Whilst working on an Ant script today I noticed that even though my classpath was defined with the classpath attribute, I still needed to use -lib when starting ant (ie ant -lib myjar.jar) to make it run properly.
<project name="My Project" default="run-task" basedir=".">
<target name="run-task" description="Use the Ant Task">
<taskdef name="TaskName" classname="mypackage.MyClass" classpath="myjar.jar"/>
<TaskName />
</target>
</project>
Is there a quirk in the classloading for ant that requires this?
The following should work the same.
<path id="ant.tasks">
<fileset dir="lib" includes="myspecialant.jar"/>
</path>
<taskdef name="TaskName" classname="mypackage.MyClass" classpathref="ant.tasks"/>
I prefer to manage my classpaths at the top of my build separate to the logic that uses them. Make troubleshooting simpler.

Error with self-bootstrapping Ant build

I'm trying to write an Ant build that does not require me adding Ant-plugins to Ant's lib directory, or /home/myuser/.ant/lib, or in my Eclipse instance's ant home, etc; namely because I will eventually be building my project on a hosted Jenkins server where I do not have access to the system's Ant installation.
I'm calling this a "self-bootstrapping" build, because I use Ivy to pull down my Ant plugins at build time, and hopefully, with some proper configuration, make their tasks available to Ant dynamically.
The jist of my build (using ant-contrib plugin as an example:
<?xml version="1.0" encoding="utf-8" ?>
<project name="myapp" default="audit" basedir="."
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:antcontrib="antlib:net.sf.antcontrib">
<!-- Build path. -->
<path id="build.path">
<fileset dir="${lib.buildtime.dir}" includes="**/*.jar"/>
</path>
<target name="bootstrap">
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="build.path"/>
</target>
<target name="resolve" depends="bootstrap">
<ivy:settings url="${ivy.settings.home}"/>
<ivy:cleancache/>
<ivy:resolve file="${ivy.xml}"/>
<ivy:retrieve pattern="${gen.lib.main.dir}/[artifact]-[revision].[ext]" conf="main"/>
<ivy:retrieve pattern="${gen.lib.test.dir}/[artifact]-[revision].[ext]" conf="test"/>
<ivy:retrieve pattern="${gen.lib.buildtime.dir}/[artifact]-[revision].[ext]" conf="buildtime"/>
<ivy:report todir="${gen.staging.dir}" />
<ivy:cachepath pathid="build.path" conf="buildtime"/>
</target>
<target name="taskdefs" depends="resolve">
<taskdef resource="/net/sf/antcontrib/antlib.xml"
uri="antlib:net.sf.antcontrib" classpathref="build.path"/>
<property name="fizz" value="buzz" />
<antcontrib:if>
<antcontrib:equals arg1="${fizz}" arg2="buzz" />
<antcontrib:then>
<echo message="Fizz is buzz!" />
</antcontrib:then>
<antcontrib:else>
<echo message="Fizz is not buzz!" />
</antcontrib:else>
</antcontrib:if>
</target>
</project>
When I run the taskdefs target, instead of seeing an echoed "Fizz is buzz!" message in my Ant output, I get the following error:
BUILD FAILED
/home/myuser/eclipse/workspace/myapp/build.xml:169: Problem: failed to create task or type antlib:net.sf.antcontrib:if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/home/myuser/eclipse/plugins/org.apache.ant_1.8.3.v201301120609/lib
-/home/myuser/.ant/lib
-a directory added on the command line with the -lib argument
Is what I am trying to do (avoid having to do 1 of the 3 recommended things above) impossible? If so, why? If not, what is wrong with my setup here? Thanks in advance!
I normally create a single "boostrap" target and use this to install ivy into the "$HOME/.ant/lib" directory. See:
Ivy fails to resolve a dependency, unable to find cause
The following is a more complete example that does what you're trying to do:
How to include ant-contrib.jar dynamically in Ant
In conclusion, it's a shame ivy is not packaged by default with ANT. If you discover your hosted service prevents you from copying files into the home directory, then perhaps the simplest thing to do is ship a copy of the ivy jar alongside your source (and enable it using a taskdef)
Update
Use the following taskdef for ant-contrib:
<taskdef uri="antlib:net.sf.antcontrib" classpathref="build.path"/>
The homepage needs update. At some stage in the recent past the library was repackaged as an antlib.

Beanshell in Ant yielding, "Unable to create javax script engine for beanshell"

Greeting, I'm trying to put some Beanshell script in my Ant build.xml file. I've followed the Ant manual as well as I can but I keep getting "Unable to create javax script engine for beanshell" when I run Ant. Here is the test target I wrote mostly from examples in the Ant manual:
<target name="test-target">
<script language="beanshell" setbeans="true">
<classpath>
<fileset dir="c:\TEMP" includes="*.jar" />
</classpath>
System.out.println("Hello world");
</script>
</target>
My beanshell "bsh-2.0b4.jar" file is on the script task's classpath the way the manual recommended. Hope I have the right file. I'm working in c:\TEMP right now.
I've been googling and trying for a while now. Any ideas would be greatly appreciated. Thanks.
First, you need jsr-engines.zip from here:
https://scripting.dev.java.net/servlets/ProjectDocumentList
Inside, you'll find jsr223/beanshell/build/bsh-engine.jar. Some searching implied that you need to download bsh-2.05b.jar. I found it here:
http://beanshell.org/bsh-2.0b5.jar
The more easily findable bsh-2.0b4.jar also seemed to work, but it printed a message that implied it was experimental.
Currently (2012) you need only 1 jar to fire the script task for BeanShell:
bsh-2.0b5.jar
Previously I also thought of the following, as mentioned by Ant Manual, Library Dependencies chapter:
bsf-2.4.0.jar
commons-logging-api-1.1.jar
But it looks like bsf is not needed for bsh, at least in my environment.
Once the jar is given to ant, the script task runs smoothly. There are 2 possible scenarios for getting the jars and making them available to ant.
Manual download way
Download the jars above. I provided the links from maven repository. Once you have all the jars downloaded, make them available to ant. There are
at least 3 ways to do it:
Put it in java library path
Put it in ant library directory
Give the correct classpath to script task.
I find the last method the best, because it is most easily ported between
different systems. The ant file for the script task could look as follows:
<project default="t1" >
<property name="bsh.path"
location="/mnt/q/jarek/lang/java/ant/stackoverflow/bsh-2.0b5.jar" />
<target name="t1">
<script language="beanshell" classpath="${bsh.path}">
javax.swing.JOptionPane.showMessageDialog(null, "Hello, Script!");
</script>
</target>
</project>
Automatic download method, employing Ivy
The manual method is not perfect when you want to distribute your build script. Then you would like a way to make sure the jars are present in the destination system. For distributing builds there's no better tool than ivy. Ivy will download the jars and put them in classpath for you. The problem is that there appears another dependency, which is ivy itself. But providing ivy.jar is quite easy and that is the last dependency we need to supply explicitly.
One may ask why to provide ivy.jar, while we could simply download bsh.jar in the same way. The answer is flexibility. When you have the ivy.jar, you get any jar you wish with a single step being adding it to the ivy.xml file. And there is an agreed universal location for the ivy.jar file, while for other file we would have to think of a suitable directory.
Below comes the full example that downloads ivy and then all the necessary dependencies. Ivy download script is based on Installation chapter of Ivy reference.
Then a simple ivy.xml file is needed, which is given after the sample build.xml.
Original auto-download ivy script has a disadvantage of always checking the ivy url, even if ivy.jar is already in the expected location. This may be overriden by specifying -Doffline=true. I prefer to add another target to the build file and to do the http check only if we don't already have the ivy.jar. This is the way the script here works. To observe what ivy actually downloaded, set IVY_HOME environment variable to a directory of your choice. It will be created and filled with ivy stuff.
build.xml:
<project default="t1"
xmlns:ivy="antlib:org.apache.ivy.ant" >
<property name="ivy.install.version" value="2.2.0" />
<property environment="env" />
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
</condition>
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<target name="check-ivy">
<condition property="ivy.present">
<available file="${ivy.jar.file}" type="file" />
</condition>
</target>
<target name="download-ivy" unless="ivy.present">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="check-ivy, download-ivy">
<!-- try to load ivy here from ivy home, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="ivy-libs" depends="init-ivy" >
<ivy:cachepath pathid="path.from.ivy" log="download-only" />
</target>
<target name="t1" depends="ivy-libs" >
<script language="beanshell" classpathref="path.from.ivy">
javax.swing.JOptionPane.showMessageDialog(null, "Hello, Script!");
</script>
</target>
</project>
ivy.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="example.com" module="testing-script-task" />
<dependencies>
<dependency org="org.beanshell" name="bsh" rev="2.0b5" />
<!-- <dependency org="bsf" name="bsf" rev="2.4.0" /> -->
</dependencies>
</ivy-module>
The Ant plug-in "org.apache.ant_1.7.0.v200803061910" have all the jar files needed
Don't use beanshell language. Use javascript instead, as it runs on jdk6 without any additional jars. Rebse told me that.
Javascript is also allowed to use java classes, for example java.lang.System.out.println()

Categories