Include all Sun-proprietary classes - java

I've got this project from sf. If I run the build file I got the error:
...\workspace_neon\ssf\main\src\org\kablink\teaming\util\Thumbnail.java:50:
error: package com.sun.image.codec.jpeg does not exist
[javac] import com.sun.image.codec.jpeg.ImageFormatException;
I found that someone else run into similar problems. How to run the build.xml file so that javac get execute with the option -XDignore.symbol.file?

In the build file in which the errors occurs try something like this
<javac ...>
...
<compilerarg value="-XDignore.symbol.file" />
</javac>

Related

libphonenumber shows a NoClassDefFoundError during the attempt to get the object instance

We are trying to get the libphonenumber to run in our java project.
The java project is running as a service on one of our servers.
On our local machines, we are using the following shell commands to include the libraries (please ignore the version numbers):
export ANT_HOME="C:\DEV\apache-ant-1.9.16"
export JAVA_HOME="C:\Program Files\Java\jdk-15.0.2"
export MAVEN_HOME="C:\DEV\apache-maven-3.8.6"
export PATH=${PATH}:${JAVA_HOME}/bin:${ANT_HOME}/bin:${MAVEN_HOME}/bin
export MB_API_HOME="C:\DEV\java-rest-api\api\target"
After we run the "ant" command, we move the result file (jar) on our server in the respective folder.
These are the 3 files that are needed for the library:
We have copied them on the server, in the respective lib folder.
Everything runs fine until the following error shows up:
java.lang.NoClassDefFoundError: com/google/i18n/phonenumbers/PhoneNumberUtil
This happens when it comes to the following line:
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
We have found the following code on this website (https://www.baeldung.com/java-libphonenumber), where it is explained that this has to go to a pom-xml file:
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.12.10</version>
</dependency>
We have no clue which pom.xml they are writing about. These are the files that are being found by IntelliJ:
IntelliJ has no problems finding the classes and their methods when we type in the code window.
What else do we have to do and consider to get it to run on the server?
Thanks in advance.
Edit 1 of ?: As g00se suggested, we already have the class path mentioned in the build.xml, which looks like this:
I had the idea of removing the libphonenumber.jar from the lib folder on the server itself to see if we receive a different error. But it is still the same NoClassDefFoundError. It is as if the result file of ant has no clue about libphonenumber at all!
Edit 2 of ?:
I have experimented with this library on my private computer.
If I click on the run icon (1), it seems to work, as seen in (2).
However, going to the folder with the Main class (3) and running java Main, leads to the same error:
But then, I just copied the classes into the folder where the Main is, and the error changed:
Here is the snippet in the build.xml of my private project:
<target name="compile" depends="init"
description="compile the source">
<!-- Compile the Java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath>
<pathelement path="jars/libphonenumber.jar"/>
</classpath>
</javac>
</target>
I guess I am missing the right approach here, do I?
Edit 3 of ?: I created a repository of my private/test project.
Here it is: https://github.com/3rc4n/libphonenumberexperiment

Ant build fails due to unfound imports in other projects

I have a java project which imports and uses classes in other projects. I am able to successfully build this project in eclipse. From eclipse I then exported an Ant Buildfile, build.xml. If I attempt to run this file with eclipse or via cmd prompt it fails.
One of the many import reported error is:
[javac] H:...\sortedprovidablemanagertest\SimpleObject.java:8: error: package com.rock.common.core.providable.abstractions does not exist
[javac] import com.rock.common.core.providable.abstractions.AProvidable;
How do I tell Ant to import required classes. I'm guessing these are dependencies. But clearly I'm having trouble setting it up correctly.
In the build.xml, there will be a <javac> task. <javac> takes either a classpath attribute or a nested <classpath> element. Here's an example with a nested <classpath> element:
<javac ...>
<classpath>
<pathelement location="PATH_TO_THE_CLASS_FILES_ROOT_DIRECTORY"/>
</classpath>
...
</javac>
The classpath tells the Java compiler where to find the binary dependencies it needs.

Ant Javac and Commandline Javac give different results

I have a class that imports some servlet libraries. When I compile it from command-line it is fine.
When I use the ant compile task to compile it, it gives the errors that it can't find the servlet libraries in its path.
Is that a known/common occurrence?
Here is my Ant target:
<target name="compile" depends="prepare" description="compile the source" >
<echo>=== COMPILE === SRCDIR: ${src}/com/udfr/src/java </echo> <!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}/com/udfr/src/java" destdir="${dist}/WEB-INF/classes"/>
</target>
It's a common occurrence if you don't specify the servlet libraries properly in the classpath for the javac task... I suspect that's the problem. If you post the task which fails and the command line which works, we'll be able to help more.
For some reason, the JAR file containing the Servlet API is part of your classpath when you compile your program in command line. However, it's not in the classpath of the javac Ant task.
You should explicitely add the JAR file to the classpath in your javac Ant task. There are several ways to do that; please read http://ant.apache.org/manual/Tasks/javac.html

Ant javac returning message "A.java added as A.class doesn't exist"

I'm writing an ANT task that is behaving very oddly. I've tried a variety of google searches with no clear answer.
I have a compile target in ANT that calls the javac command:
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}:${unittest.src.dir}" destdir="${classes.dir}">
<classpath refid="classpath" />
<exclude name="**/plugins/**" />
<exclude name="**/outbound/**" />
</javac>
</target>
That generates no errors, but when I run ant with the -verbose and -debug tags I get the following in my logs:
[javac] package/MyClass.java added as package/MyClass.class doesn't exist
So it's not erroring out, but it is giving me this odd result (with the "doesn't exist" appended at the end). Obviously this causes later targets to fail when it tries to run the classes (in this case, my junit target).
Web searches seem to indicate that I'm either missing a java_home env variable or that there is a versioning issue somewhere along the line (this error tended to occur when the source attribute on javac was set, but I removed that and am still getting the odd result). I believe we've got those possibilities covered.
Any thoughts or advice on this would be wonderful. Thanks.
I don't know too much about ant, but I would almost guess this error message is a red herring. I think it's just reporting that MyClass.java was added to the list of files to compile, because the compiled version of the class was not found on the class path. This seems to be supported by the fact that the task does not fail.
What are the later errors you are getting?

"cannot find symbol" when compiling with Ant

I need to generate an apk file using an Ant script, but I'm having problems with the compile target. To automatically generate the Ant script, I've used the Android tool with the command android update project. The problem is that this project depends on another project, so I need to use a custom compile task.
For that reason, I've overridden that target: I've copied the compiled task from ant_rules_r3.xml and I've changed the javac task like this (see comments for what I changed):
<!--I've changed the target 1.5 to target 1.6 -->
<javac encoding="UTF8" target="1.6" debug="true" extdirs=""
destdir="${out.classes.absolute.dir}"
bootclasspathref="android.target.classpath"
verbose="${verbose}"
classpath="${extensible.classpath}"
classpathref="android.libraries.jars">
<src path="${source.absolute.dir}" />
<!--My project has two src directories -->
<src path="${source2.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<src refid="android.libraries.src" />
<!--I've added here the src dir of the other project -->
<src path="${dep1.source.absolute.dir}"/>
<classpath>
<!--I've added here the lib dir of the other project -->
<fileset dir="${dep1.external.libs.absolute.dir}" includes="*.jar" />
<fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
</classpath>
</javac>
The problem is that when I compile with ant compile, I get the following error:
[javac].... cannot find symbol
[javac] symbol : constructor IOException(java.lang.String,java.security.NoSuchAlgorithmException)
[javac] location: class java.io.IOException
[javac] throw new IOException("Algorithm not found", e);
It seems as though it's been compiled with JDK 1.5 instead of 1.6 even though I have set the target property to 1.6. My computer is using Java version 1.6.0_20.
I've tried using javac compiler="javac1.6", but I get the same error.
I've also set in my build.properties:
ant.build.javac.target=1.6
ant.build.javac.source=1.6
but it doesn't solve the problem either. Setting it to 1.3 instead of 1.6 causes more errors, so it seems it is using the JDK I'm setting here.
How can I get this to compile correctly?
Because you've specified the bootclasspath to use the Android SDK classes, these will probably be the ones that contain the IOException class that does not implement the two-arg constructor with a Throwable second arg. That constructor was new in Java 6, but according to recent Android (2.2) docs, the Android version only has Java-1.5 style constructors, and doesn't implement the two newer constructors that take Throwable args.
You didn't mention whether you'd got this to build successfully before bringing in the second project - so I'd recommend checking your local Android boot classes to see what constructors IOException offers.

Categories

Resources