Ant compiling but not running or creating jar


Ant compiling but not running or creating jar



The Ant build below compiles successfully.



Unfortunately, it doesn't execute the run step despite the depends attribute specifying execute the run target after compile step completed successfully.


depends



It also doesn't create a jar file in the specified classpath.



build.xml


<?xml version="1.0" encoding="UTF-8"?>

<project default="run" name="My Project">
<target name="run" depends="compile">
<java classname="com.company.program.project">
<classpath path="staging" location="C:my_workEclipse3.6-64plugins"/>
</java>
</target>

<target name="compile">
<javac includeantruntime="false" srcdir="./src" destdir="staging">
<classpath>
<fileset dir="C:my_workEclipse3.6-64plugins">
<!-- <include name="**/*.jar" /> -->
<include name="org.eclipse.swt.*.jar" />
</fileset>
</classpath>
</javac>
</target>

<jar destfile="./build/jars/swtgui.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="org.swtgui.MainGui" />
<attribute name="Class-Path" value="." />
</manifest>

<fileset dir="./bin/com/company/program/project" includes="**/*.class" />
<fileset dir="C:my_workEclipse3.6-64plugins" includes="org.eclipse.swt.win32.win32.x86_64_3.6.0.v3650b.jar" />

</jar>

<record name="./project.log" loglevel="verbose" action="start"/>





EDIT: Got it to run. Did not edit the build.xml, but went to Project Explorer -> build.xml -> External Tool Configurations -> Build -> Targets and for some reason the run target was unchecked.


Project Explorer -> build.xml -> External Tool Configurations -> Build -> Targets



I checked it and now the run target runs, but produces the error log below.


run


run:
[java] running com.company.project.program with default permissions (exit forbidden)
[java] Running in same VM Executing 'com.company.project.program'
The ' characters around the executable and arguments are
not part of the command.
[java] Could not find com.company.project.program. Make sure you have it in your classpath
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:140)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:834)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:228)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:137)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:110)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:460)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:142)
[java] Java Result: -1
run: duration 0 seconds
BUILD SUCCESSFUL

BUILD SUCCESSFUL



Do I need to do anymore editing to the xml file to get this to run and create a jar?





Do not use ant. Use maven or gradle
– Jens
Jul 1 at 18:34





I'm forced to use ant. :(
– lolololol ol
Jul 1 at 18:35





Try running ant -verbose -debug and check/post the output. Absolute Windows paths are a pretty bad sign, but I'm not sure this is the problem. Generally your build file does not look good.
– lexicore
Jul 1 at 19:33


ant -verbose -debug





I believe I am running in verbose mode (see last line in xml file) but the console output is still nothing.
– lolololol ol
Jul 1 at 19:35





@lololololol Please use @username in your comment to address a specific user you're replying to.
– lexicore
Jul 1 at 19:36


@username




1 Answer
1



Your jar step is not inside a "target". Create a target named "jar" that depends on "compile", that creates a jar (your "jar" block should work here), and have target "run" depend on it.



It looks like you will need to add the jar you create to your "run" "java" classpath as well.





But the run target is not even running.
– lolololol ol
Jul 1 at 21:00





What command are you using to invoke Ant, and what is the output you are seeing?
– John Elion
Jul 1 at 21:32





I right-click on the build.xml file and click Run As -> Ant Build.
– lolololol ol
Jul 1 at 21:39


build.xml





Your IDE is running the 'compile' target. I don't know your IDE, so I don't know what to tell you to do differently.
– John Elion
Jul 1 at 22:22





The key is the line "Build sequence for target compile is..." - that is the target it is processing. The fact that it also tells you the complete build sequence may be misleading you.
– John Elion
Jul 1 at 22:24






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?