Javac cannot find SWT library despite correct classpath

Multi tool use
Javac cannot find SWT library despite correct classpath
I have a Java project that uses SWT and compiles/runs perfectly.
When I try to compile via Ant, however, javac cannot find the SWT library despite the build.xml specifying the correct classpath.
The SWT library is located in C:my_workEclipse3.6-64plugins
. As seen below (under the javac
tags, this classpath is specified as such.
C:my_workEclipse3.6-64plugins
javac
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 path="C:my_workEclipse3.6-64plugins"></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="./MyProject.log" loglevel="verbose" action="start"/>
The above gives me errors on import statements such as the following:
error: package org.eclipse.swt does not exist
import org.eclipse.swt.SWT;
^
Why does javac not find the SWT library when the classpath is correctly specified?
Also how can I find out where javac is looking? The logs -- even in verbose mode -- tell me nothing about where javac is trying to find these import statements.
2 Answers
2
it seems <classpath path="C:my_workEclipse3.6-64plugins"></classpath>
is not adding dependencies to compile classpath
<classpath path="C:my_workEclipse3.6-64plugins"></classpath>
this way works for me:
<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>
SWT provides a separate Jar for standalone Java applications.
You can download the latest one from here - look at the 'SWT Binary and Source' section near the bottom of the page.
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.
Your change worked, but the run target doesnt execute now. The jar file is also not being created. Do I need to do something similar to get that to work?
– lolololol ol
Jul 1 at 19:21