issue building Java class from xsd using JAXB - java

I am using ant to build my legacy project in which we generate Java class from XSD using JAXB and below is the ant config I have. JAXB parser is getting invoked properly and Java classes are getting created without any issue but ant stops building my project further after it invokes com.sun.tools.xjc.XJCFacade class. Even the echo statement message="Finished creating JAXB class" doesn't get executed. I don't get any error message from ant build but it stops after creating the java classes. Not sure what the issue is; would really appreciate if someone could help me with this issue.
<target name="compile" >
<echo message="start creating JAXB class" />
<java classname="com.sun.tools.xjc.XJCFacade"/">
<arg value="input.xsd"/>
<arg value="-b"/>
<arg value="input.jxb"/>
<arg value="-d"/>
<arg value="target.dir"/>
<classpath>
<pathelement path="classpath"/>
</classpath>
</java>
<echo message="Finished creating JAXB class" />
</target>

Related

Error Failed to open properties file : AppManage.tra from Ant script

After building EAR file when i'm trying to extract XML file form the EAR i'm getting error [exec] Failed to open properties file : AppManage.tra
<property name="Appmanage" value="C:\tibco\etascbw513\tra\5.10\bin\AppManage.exe" />
<target name="extract">
<exec executable="${Appmanage}">
<arg value="-export"/>
<arg value="-ear"/>
<arg value="${workdir}\Deploy\EARs\${project}.ear"/>
<arg value="-out"/>
<arg value="${workdir}\Deploy\EARs\${project}.xml"/>
<arg value="-max"/>
</exec>
old Q : can someone share simple build.xml to create ear file from ant script
details : i'm able to pull repositories with the help ant script now i want to create EAR file from ant script for Tibco BW. can any one share simple demo .
try to solve this error using below steps.
try to check your environment variable path.
check TRA_HOME/bin/ using App manage utility.
This error "Failed to open properties file : AppManage.tra" occurs because the AppManage executable tries to look for AppManage.tra in the current execution directory and does not find it. In this particular case, the current execution directory would depend on where you are executing Ant from.
The correct way to avoid this error is to provide full path to the AppManage.tra file as an argument to the AppManage executable in the ant exec statement, as shown below, in the highlighted section (two new arguments are added "--propFile" and "full path to AppManage.tra"). Hope this helps.
<property name="Appmanage" value="C:\tibco\etascbw513\tra\5.10\bin\AppManage.exe" />
<target name="extract">
<exec executable="${Appmanage}">
<arg value="--propFile"/>
<arg value="C:\tibco\etascbw513\tra\5.10\bin\AppManage.tra"/>
<arg value="-export"/>
<arg value="-ear"/>
<arg value="${workdir}\Deploy\EARs\${project}.ear"/>
<arg value="-out"/>
<arg value="${workdir}\Deploy\EARs\${project}.xml"/>
<arg value="-max"/>
</exec>

Ant Javac Task Deletes Method

I have run into some trully bizarre behavior in a Java project. The situation is that javac seems to be removing a method from a class during compilation.
The class looks something like this:
public class MessedUp extends X {
//a bunch of variables here
//a bunch of methods here
public void thisDisappears(String arg){
}
//a bunch more methods here
}
There is another class that instantiates and calls this method:
public class WontCompile {
public void doSomething(){
MessedUp mu = new MessedUp();
mu.thisDisappears("something");
}
}
The first class compiles just fine, but the second doesn't. javac outputs something like the following:
[javac] C:\mypath\WontCompile.java:251: error: cannot find symbol
[javac] mu.thisDisappears("something");
[javac] ^
[javac] symbol: method thisDisappears(String)
[javac] location: variable mu of type MessedUp
I know that the code is fine because I have been using it in Eclipse for a couple of years (I'm tracking down this problem as I try to use the ant file Eclipse produced). However, once in a while Eclipse will highlight the call to thisDisappears, saying it doesn't exist, and offering to create it. If accept the offer, then Eclipse complains that there are two methods with the same name. After a little bit of finagling which apparently causes a rebuild or something, the error goes away.
After being driven up the while for a while, I decided to check the actual class file for MessedUp.java. Using the Java Decompiler GUI, I found that thisDisappears isn't present in the class file!
Below is my ant file:
<project basedir="." default="build" name="MyProject">
<property name="LIB_HOME" value="C:\dev\LibSuite-9.3.1"/>
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="MyProject.classpath">
<pathelement location="bin"/>
<pathelement location="lib/edu.mit.jwi_2.1.4.jar"/>
<pathelement location="lib/edu.sussex.nlp.jws.beta.11.jar"/>
<pathelement location="lib/jaws-bin.jar"/>
<pathelement location="lib/junit-4.11.jar"/>
<!--External Jars-->
<pathelement location="${LIB_HOME}/share/java/abc.jar"/>
<pathelement location="${LIB_HOME}/share/java/def-9.3.1.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="main/src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="bin">
<fileset dir="main/test">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="init" name="build">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<classpath refid="MyProject.classpath"/>
<src path="main/src"/>
<src path="main/test"/>
<compilerarg value="-Xlint"/>
</javac>
</target>
<!--Test the app-->
<target depends="build" name="regression">
<junit>
<classpath refid="MyProject.classpath"/>
<test name="uni.my.app.TestSuite"/>
</junit>
</target>
<!--Run the app-->
<target depends="build" name="run">
<java classname="uni.my.app.Application">
<classpath refid="MyProject.classpath"/>
<arg value="sentences.txt"/>
</java>
</target>
</project>
Unfortunately, I was unable to put together a minimum breaking example. The code I am working on is not yet released to the public, so I can't share it all yet. It references several jars (with no conflicting namespaces), some with native methods. I have no idea what exact combination of classes and jars causes the error. I had the same problem using jdk 1.6.0_25 and 1.7.21.
Does anyone have any experience or ideas on how to solve this problem?
This is a guess.
Ant operates outside of eclipse, and therefore any changes it makes are not reflected in eclipse's massively cached view of the world. For all I know, eclipse's changes are not reflected in files that ant uses, either.
I would do a project clean, then a project build, then a project refresh. I would see if you have this problem from within eclipse. Then I would run ant (if I must), do another refresh, and see if the problem exists then.
Any time you do anything in either eclipse or ant, before you use the other program, refresh the eclipse project.
Let us know how it goes.
p.s. trust that the java compiler is not removing any methods. I agree you have something strange going on, but that isn't it.
The problem was that, for whatever reason, another user had turned the project into the VCS with all of the class files in the same folders as their corresponding sources. On my machine, Eclipse puts the binaries into the bin folder, so I don't know why they were placed with the source on the other user's machine.
The init target generated by Eclipse is meant to copy over resources used by the code. It copies over anything but java or launch files from the source directories. However, since the class files were in the source directories, it copied them over, too. Then, when the build target was executed, it didn't bother compiling anything because it seemed that there were already fresh class files present (but they were actually just fresh copies of old code).
The solution was to 1) remove all of the class files from the source folders and 2) add exclude rules for **/*.class to the resource copying code, for good measure.

How to specify input parameters for <java jar="sth.jar" fork="true"/> in build.xml of Ant?

This may be a naive question for the people who are familiar with Ant. I am new to Ant. please do me a favor. Thanks!
I write something like this in build.xml.
<target name="run">
<java jar="build/jar/sth.jar" fork="true"/>
</target>
But, I want to put some parameters to it, like
java -jar build/jar/sth.jar input.txt
How to do that?
By the way, where could I find the specifications of build.xml grammar? like how many attributes are there? what are the other attributes rather than "jar" "fork"?
This should do what you want:
<exec executable="java">
<arg value="-jar" />
<arg value="build/jar/sth.jar" />
</exec>
Here is the source of documentation http://ant.apache.org to start with.
EDITED:
You can use java tag as well, simply specifying tag args="input.txt" or whatever parameters you would like to pass. More info on java command
<java jar="build/jar/sth.jar">
<arg value="input.txt" />
</java>

Passing system properties to tomcat managed webapp when started by another process

The startUp script of webapp is going to be executed by a standalone java management process. I understand that -D system properties can be set to CATALINA_OPTS in catalina.sh. So is the only way to pass system properties is for the java management process to go write into catalina.sh? I
I think this should be possible, but dont have the exact answer.
If it can be passed in an ant task like shown on this link, I assume it should be able to call the
org.apache.catalina.startup.Bootstrap load() passing in JVM args
<target name="tomcat-start">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
</java>
</target>
<target name="tomcat-stop">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
<arg line="stop"/>
</java>
</target>

Running a class from within a jar using ant

im trying to invoke a specific class from within a jar file but I'm gettign below exception -
Buildfile: C:\Projects\GranHermano\build.xml
SignJadFilesInDir:
[java] java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell
My jar file contains all required jars (in this case poi-3.6-20091214.jar) so above exception should not be thrown.
This is how I am invoking the class -
<target name="SignJadFilesInDir" description="Signs all jad files in a dir" >
<java classname="com.src.SignDeviceJadInDir">
<classpath>
<pathelement location="BuildUtils.jar"/>
</classpath>
<arg line="${jadFileDir}"/>
<arg line="${devicesExcelDir}"/>
<arg line="${wtkDir}"/>
<arg line="${keyStoreDir}"/>
<arg line="${keyStoreId}"/>
<arg line="${keyStorePwd}"/>
</java>
</target>
Thanks
Can you please open jar BuildUtils.jar to ensure it well contains the classes of poi (and not poi jar, as I'm not aware of JRE support for jar-in-a-jar out of the box) ?
If your BuildUtils.jar contains poi-3.6-20091214.jar and not its classes, your exception is quite normal.

Categories