When using ant in eclipse, standard input does not work? - eclipse

In demo.Main.main method I do
System.in.read()
In build.xml there is the target
<target name="run">
<java classname="demo.Main" fork="false">
<classpath refid="classpath" />
</java>
</target>
When I go to Eclipse's Console and I give something in , System.in.read() does not see it.

Ant does not support System.in.read().
Use the Ant task <input> for user input instead.

Related

.war file won't be updated

I have an old project, built using Google Web Toolkit in Eclipse. When I created it, I did the following steps, in order to get the .war file
GWT Compile Project
Run the following Ant script
<project name="The" basedir="." default="default">
<target name="default" depends="buildwar,deploy"></target>
<target name="buildwar">
<war basedir="war" destfile="The.war" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="The.war" todir="." />
</target>
</project>
Get the .war file
Now, I had to change a port in my project, so I changed it in my code and did the same steps in order to get the .war
However, when I deploy my updated project in Tomcat, it still makes requests to the old port number (I found this reading catalina.out)
So, What can I do in order to get a new, fresh .war ???
You don't mention it, but did you change the ports in tomcat? I assume you did, but I just want to cover all possibilities.

acceleoCompiler not showing output in console output with ant

I am using acceleoCompiler inside an ant script and when i run the ant script everything shows an output except acceleoCompiler.
For instance, [javac] and [mkdir] shows up. But nothing relating to acceleoCompiler shows up. Am i doing something wrong?
The ant script:
<eclipse.refreshLocal resource="${F_FOLDER}/bin/" depth="infinite"/>
<eclipse.refreshLocal resource="${FE_FOLDER}/bin/" depth="infinite"/>
<mkdir dir="${F_OUTPUT}"/>
<mkdir dir="${FE_OUTPUT}"/>
<javac
srcdir="${F_SRC}generator/"
destdir="${FR_OUTPUT}"
executable="${JAVA_JDK}/javac"
fork="true"
includeantruntime="false"
failonerror="false"
/>
<javac
srcdir="${FE_SRC}generator/"
destdir="${FE_OUTPUT}"
executable="${JAVA_JDK}/javac"
fork="true"
includeantruntime="false"
failonerror="false"
/>
<acceleoCompiler sourceFolder="${F_SRC}"
outputFolder="${F_OUTPUT}"
dependencies=""
binaryResource="true"
packagesToRegister="org.eclipse.emf.ecore.EcorePackage">
</acceleoCompiler>
<acceleoCompiler sourceFolder="${F_SRC}"
outputFolder="${FE_OUTPUT}"
dependencies=""
binaryResource="true"
packagesToRegister="org.eclipse.emf.ecore.EcorePackage">
</acceleoCompiler>
The absence of logging messages doesn't mean you're doing anything wrong. If you look at the source for mkdir or javac you'll see that they call the Ant Task method log() in most cases. The Acceleo Ant task however only calls log() if it finds a problem - if all is well it is silent and enigmatic.
References:
Ant mkdir task source.
AcceleoCompiler source via the Acceleo wiki FAQ.

How can someone run RequestFactory's ValidationTool from ant?

I use:
<java failonerror="true" classname="com.google.web.bindery.requestfactory.apt.ValidationTool">
<arg path="${path.to.ouput.jar}" />
<arg value="com.my.RequestFactory" />
<classpath>
<path refid="my_classpath" />
</classpath>
</java>
my_classpath has all requestfactory-client.jar, requestfactory-server.jar, requestfactory-apt.jar + my source & the jar produced from it in the path (that's confirmed with just printing it), but I still get:
[java] error: Unable to find RequestFactory built-in type. Is requestfactory-[client|server].jar on the classpath?
What could be wrong here?
For me, this works only, if I specify <javac fork="true" ...
From the official ant documentation on the java task:
If odd things go wrong when you run this task, set fork="true" to use a new JVM.
Without any deep investigation, I would say it's most likely a classloader problem.

script to execute the eclipse PDE Tools > Build site

i want to write a script to do the Build site of plugin Update site site.xml?
i could not find a way to do this?
i found very easy to build a plugin feature. I can automatically creat the ant file build.xml via eclipse but i could not find the same for the update site.xml
thank you all
stefania
Are you trying to build an Eclipse plugin from Ant? You want to use the Ant4Eclipse external add-on for Ant. It lets you build the run-configurations you've made in Eclipse (right click>run as>...) from your .project file. You can download it here and there is a tutorial here.
I attempted to do what you're asking at a previous job without using Ant4Eclipse, I don't remember how I got it working, but I do remember it being extremely difficult.
Edit: you can build an Eclipse update site from the command line, which can be run from Ant. There is some [possibly out of date] documentation here, but I found you a sample from an Apache projects build.xml:
<target name="build-site" depends="init">
<copy todir="target/eclipse-update-site/web" preservelastmodified="true">
<fileset dir="web"/>
</copy>
<copy todir="target/eclipse-update-site" file="index.html" preservelastmodified="true"/>
<copy todir="target/eclipse-update-site" file="site.xml" preservelastmodified="true"/>
<!-- copy all the features to the target -->
<copy todir="target/eclipse-update-site/features" preservelastmodified="true" >
<fileset dir="features"/>
</copy>
<!-- see http://wiki.eclipse.org/Update_Site_Optimization -->
<java jar="${eclipse.home}/plugins/org.eclipse.equinox.launcher.jar" fork="true" failonerror="true"
maxmemory="256m">
<arg line="-application org.eclipse.update.core.siteOptimizer"/>
<arg line="-digestBuilder -digestOutputDir=target/eclipse-update-site"/>
<arg line="-siteXML=target/eclipse-update-site/site.xml"/>
</java>
</target>

How can I automate (script) creating a war file in eclipse?

It's 5 button clicks to get eclipse to create a deployable war file for my eclipse project, I figure there's probably some eclipse command line option to do the same thing, so I can just write it into a script, but I'm not seeing it.
Use the Ant war task, set up a relevant build file and you can just hit the "external tools" button to execute it.
You could also setup a Maven build for your web project. Typing mvn package from the command line would then build the project for you.
For integration between Maven and Eclipse, see m2Eclipse and Maven Eclipse Plugin.
I cannot say anything about the WAR packaging itself, sorry.
But as I wrote in
How do I automatically export a WAR after Java build in Eclipse? : If you can describe the WAR packaging with an Ant script, you can have that Ant script being executed automatically after each change to your project. Use Project->Properties->Builders->Add->Ant Builder. Give that builder you custom Ant script and it will automatically be executed after the "normal" builders of your project.
You can even specify in the settings of the builder, if it shall only react on changes to specific files and so on.
The Ant builder is kind of a Swiss army knife for anything you want to automate in the project build without having to use the big tools like maven.
This Ant script should work for standard Dynamic Web Project structure of project:
Create Ant build.xml with replacing of two properties at begining:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Deploy From Eclipse to JBoss" basedir="." default="deploy">
<!-- This replace with yours project name and JBoss location: -->
<property name="warfile" value="MyProject"/>
<property name="deploy" value="/home/honza/jboss-as-7.1.1.Final/standalone/deployments"/>
<target name="create">
<war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
<classes dir="build\classes"/>
<fileset dir="WebContent">
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="copy">
<copy todir="${deploy}" overwrite="true">
<fileset dir=".">
<include name="${warfile}.war"/>
</fileset>
</copy>
</target>
<target name="clear">
<delete includeemptydirs="true">
<fileset dir="${deploy}" defaultexcludes="false">
<include name="${warfile}.*/**" />
</fileset>
</delete>
</target>
<target name="deploy">
<antcall target="create"/>
<antcall target="clear"/>
<antcall target="copy"/>
</target>
</project>
Now should command "ant" do WAR creation and copy them to the JBoss. JBoss automatically deploys wars which finds in deployment directory.
For automatic run after build (Project - Build) add this Buildfile here:
MyProject - Properties - New - Ant builder