0

I have a J2EE program that I have been maintaining since 2006/7. The Ant build compiles all Java/J2EE code, creates the database in MySql and imports data into it, and deploys the build (exploded) war into Tomcat.

There's been no changes to the code in years. The only changes are in the stack - where I was forced to update the versions of Java (1.8), MySql (5.5), Eclipse, and lately, Windows (11).

This build runs flawlessly and I'm able to launch the website and run it successfully. The only thing that's changed is that somehow I'm unable to run the Ant build from inside Eclipse now.

I created the Eclipse project by importing the existing source folder. Then I created the 'Ant build' in the 'External Tools Configuration'. (I've been doing this in Eclipse since 2004, so I know the overall configurations I need to make.)

But somehow, either something's changed in Eclipse that I can't put my finger on or because I'm making a really silly error without knowing what it is, the Ant build from inside Eclipse keeps failing.

I've been trying all kinds of things to fix the Classpath, but nothing seems to work. This exact same build works with no changes from the command prompt. So, it's not a question of missing libraries - just finding them.

What's happening? Please help!

DETAILS:

Ant target 'compile':

<!-- Normal build of application -->
<target name="compile" depends="prepare,copy-resources">
    <javac srcdir="src/java" destdir="${webinf.dir}/classes" debug="true">
        <classpath refid="compile.classpath" />
    </javac>

Error in execution of 'compile':

compile:
    [javac] <PROJECT_LOC>\ant\build.xml:163: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 439 source files to C:\<src_root_folder>\WebContent\WEB-INF\classes
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:32: error: package javax.xml.bind does not exist
    [javac] import javax.xml.bind.JAXBException;
    [javac]                      ^
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:33: error: package javax.xml.bind does not exist
    [javac] import javax.xml.bind.Marshaller;
    [javac]                      ^
    [javac] <PROJECT_LOC>>\src\java\com\cs\service\rest\GeoCodeClient.java:34: error: package javax.xml.bind does not exist
    [javac] import javax.xml.bind.JAXBContext;
    [javac]                      ^
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:52: error: cannot find symbol
    [javac]     protected Marshaller marshaller;
    [javac]               ^
    [javac]   symbol:   class Marshaller
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:87: error: cannot find symbol
    [javac]     private Marshaller newMarshaller() {
    [javac]             ^
    [javac]   symbol:   class Marshaller
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\util\PasswordService.java:26: error: cannot find symbol
    [javac] import sun.misc.BASE64Encoder;
    [javac]                ^
    [javac]   symbol:   class BASE64Encoder
    [javac]   location: package sun.misc
...
...
...
   [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:89: error: cannot find symbol
    [javac]             JAXBContext jc = JAXBContext
    [javac]             ^
    [javac]   symbol:   class JAXBContext
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:89: error: cannot find symbol
    [javac]             JAXBContext jc = JAXBContext
    [javac]                              ^
    [javac]   symbol:   variable JAXBContext
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:92: error: cannot find symbol
    [javac]             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
    [javac]                                    ^
    [javac]   symbol:   variable Marshaller
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:95: error: cannot find symbol
    [javac]         } catch (JAXBException jaxbe) {
    [javac]                  ^
    [javac]   symbol:   class JAXBException
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:102: error: cannot access JAXBContext
    [javac]             RequestHeader header = factory.createRequestHeader();
    [javac]                                           ^
    [javac]   class file for javax.xml.bind.JAXBContext not found
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:103: error: cannot access Element
    [javac]             header.setClientName(clientName);
    [javac]                   ^
    [javac]   class file for javax.xml.bind.Element not found
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:108: error: cannot find symbol
    [javac]         } catch (JAXBException jaxbe) {
    [javac]                  ^
    [javac]   symbol:   class JAXBException
    [javac]   location: class GeoCodeClient
    [javac] <PROJECT_LOC>\src\java\com\cs\service\rest\GeoCodeClient.java:128: error: cannot find symbol
    [javac]         } catch (JAXBException jaxbe) {
    [javac]                  ^
    [javac]   symbol:   class JAXBException
    [javac]   location: class GeoCodeClient
...
...
...
    [javac] <PROJECT_LOC>\src\java\com\cs\util\PasswordService.java:51: error: cannot find symbol
    [javac]         String hash = (new BASE64Encoder()).encode(raw);
    [javac]                            ^
    [javac]   symbol:   class BASE64Encoder
    [javac]   location: class PasswordService
    [javac] <PROJECT_LOC>\src\java\com\cs\util\gis\DeCartaGeoCodeService.java:102: error: cannot find symbol
    [javac]         } catch (JAXBException e) {
    [javac]                  ^
    [javac]   symbol:   class JAXBException
    [javac]   location: class DeCartaGeoCodeService
    [javac] <PROJECT_LOC>\src\java\com\cs\util\gis\DeCartaGeoCodeService.java:166: error: cannot find symbol
    [javac]         } catch (JAXBException e) {
    [javac]                  ^
    [javac]   symbol:   class JAXBException
    [javac]   location: class DeCartaGeoCodeService
    [javac] <PROJECT_LOC>\src\java\com\cs\util\gis\DeCartaGeoCodeService.java:263: error: cannot find symbol
    [javac]         } catch (JAXBException e) {
    [javac]                  ^
    [javac]   symbol:   class JAXBException
    [javac]   location: class DeCartaGeoCodeService

2 Answers2

1

javax.xml.bind was deleted in JDK11, or 9 or.. something after 8. JDK9 broke a ton of stuff. In eclipse you're compiling on JDK9+, on the command line you're compiling vs JDK8. Edit your eclipse project to use JDK8. Alternatively, see this answer about fixing javax.xml.bind.

You probably also have to replace sun.misc.BASE64; JDK8+ ships with base64 built in, for what its worth - just use that. sun.misc was never really public API, which is possibly why it was unceremoniously just removed.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • You're right about all that - except I am using jdk1.8.0_202. I have gone down this rabbit hole several times for the last two years since I have been forced to update my Eclipse. I don't want (need) to fix things are not broken (yet). Just need to be able to build/run/debug the code from within Eclipse. I'm guessing I'll have to get down to an earlier version of Eclipse. – Agile Entrepreneur Feb 14 '23 at 22:57
  • No, eclipse downgrading has no effect on this whatsoever. Eclipse isn't itself a JDK, instead it has a way to configure as many JDKs as you like as 'available', then, per project, you can pick one it should use. That's the settings you need to be changing here. In window/preferences, use the filter to search for 'Installed JREs'. Make sure a JDK1.8 is in there. Then in your project settings (right click, properties), section 'java compiler', pick 1.8. – rzwitserloot Feb 15 '23 at 09:44
0

Eclipse can't run Ant internally with the version of Java you want to use. The bridging code it uses was compiled for Java 11 so that it wouldn't simply break with Java 18 onward, and those new Java versions keep coming, so it's run using Java 11 or higher. Because of that requirement, you're running up against Java 11 having removed several packages that were in Java 1.8, like javax.xml.bind (it was deprecated in Java 9).

You probably should update that stack at some point, though. The MySQL version you're using is years out of support.

nitind
  • 19,089
  • 4
  • 34
  • 43
  • That makes sense. For the time being, I'd rather fix this build with minimal changes. I don't have the resources right now to port this product to later (versions of) technologies. Looking at: https://wiki.eclipse.org/Eclipse/Installation#:~:text=Eclipse%204.14%20(2019%2D12),-Eclipse%204.14%20(2019&text=A%20Java%208%20or%20newer%20JRE%2FJDK%20is%20required%20to,as%20well%20as%20the%20Installer. I see that the Eclipse 4.16 (2020-06) is the last supported version for JDK 1.8. I'm going to try and download this version of Eclipse. (Can't find it yet.) – Agile Entrepreneur Feb 14 '23 at 23:13
  • Being over 15 months old, you should check either https://www.eclipse.org/downloads/packages/ ("MORE DOWNLOADS" section) or https://archive.eclipse.org/eclipse/downloads/ . – nitind Feb 14 '23 at 23:29
  • That worked! With no changes. (This may or may not be related, but for some reason, Eclipse can't read a property for my Tomcat location in my custom ant properties file - that works fine from the command line. But this is a minor issue, and can reasonably be considered an Ant / environment issue, with several simple workarounds until I figure out what's going on there.) Thank you! – Agile Entrepreneur Feb 15 '23 at 01:30