Ant cannot compile with cross-release process - java

I have a ant process to compile a java 1.8 application. Ant is lauched from Eclipse IDE in Windows running with java 1.17.
If I try to run Ant process using a separate JDK (1.8), different from the workspace one, I got this error:
I tried to run Ant with the same version of Eclipse (1.17), I had to add these attributes to <javac> element:
target="8" source="8" release="8"
The compilation starts, but it fails with this error:
java.lang.IllegalAccessError: class org.adrianwalker.multilinestring.JavacMultilineProcessor (in unnamed module #0x4778ea49) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module #0x4778ea49
The failing class (JavacMultilineProcessor) is a annotation processor class.
(http://www.adrianwalker.org/2011/12/java-multiline-string.html)
Do you have any idea what happened?

I solved with some other attributes to javac element:
<javac fork="true" executable="C:\Program Files\Java\jdk1.8.0_202\bin\javac" includeantruntime="false" ... />

Related

ant error while compiling typedef A class needed by class IvyAntSettings cannot be found

I have an ant project with build.xml and ivy.xml setup.
when I run the "ant" command line or I use intellij to build the jar (with -compile) I am getting this error:
BUILD FAILED
build.xml : the following error occurred while executing this line:
jar:file:/C:/java/jdk1.8.0_351/jre/lib/ext/ivy-2.3.0.jar!/org/apache/ivy/ant/antlib.xml:21: type def A class needed by class org.apache.ivy.IvySettings cannot be found: org/apache/tools/types/DataType using the classloader AntClassLoader[]
...
Caused by: java.lang.NoClassDefFoundError: org/apache/tools/types/DataType
I tried ivy version 2.3.0, 2.4.0, 2.5.0, 2.5.1, ant version 1.10.5, 1.10.10, 1.10.12.
My ANT_HOME and JAVA_*HOME are set properly and ANT_*HOME is in PATH
I can create run configuration and the service runs properly, I can access API/REST, no compile errors.
I am not sure what else to check
The problem is I had the jar files in multiple location. I removed it from the $ANT_HOME/lib/ant/lib folder and it worked.

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.

cannot build JavaFX 2.1.0 sample application - DataApp - failed to create task or type javafx:com.sun.javafx.tools.ant:application

I am trying to build the DataApp sample application from the JavaFX 2.1.0 sample application pack downloadable from the official JafaFX downloads page:
http://www.oracle.com/technetwork/java/javafx/downloads/index.html
I am using Netbeans 7.1.2, JDK6 and JavaFX 2.1.0 for JDK6.
In NetBeans, when I right-click on the DataApp server and select Run from the context menu, I get the following output:
check-mysql-drivers-installed:
init:
deps-module-jar:
DataAppClient.init:
Deleting: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\built-jar.properties
DataAppClient.deps-jar:
Updating property file: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\built-jar.properties
DataAppLibrary.init:
DataAppLibrary.deps-jar:
Updating property file: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\built-jar.properties
DataAppLibrary.compile:
Copy libraries to D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppLibrary\dist\lib.
To run this application from the command line without Ant, try:
java -jar "D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppLibrary\dist\DataAppLibrary.jar"
DataAppLibrary.jar:
Duplicated project name in import. Project jfx-impl defined first in D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\nbproject\jfx-impl.xml and again in D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppPreloader\nbproject\jfx-impl.xml
DataAppPreloader.init:
DataAppPreloader.deps-jar:
Updating property file: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\built-jar.properties
DataAppPreloader.compile:
Copying 1 file to D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppPreloader\build
Copy libraries to D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppPreloader\dist\lib.
To run this application from the command line without Ant, try:
C:\jdk1.6.0_30/bin/java -jar "D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppPreloader\dist\DataAppPreloader.jar"
Deleting directory D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppPreloader\dist\lib
Detected JavaFX Ant API version 1.1
DataAppPreloader.jfx-deployment:
DataAppPreloader.jar:
DataAppClient.compile:
Copying 27 files to D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib
Moving 1 file to D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\DataAppLibrary.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jackson-core-asl-1.7.1.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jackson-jaxrs-1.7.1.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jackson-mapper-asl-1.7.1.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jackson-xc-1.7.1.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jersey-client-1.8.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jersey-core-1.8.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Expanding: D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib\jersey-json-1.8.jar into D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build\classes
Deleting directory D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\dist\lib
D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppServer\nbproject\build-impl.xml:559: The following error occurred while executing this line:
D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build.xml:48: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:application
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
BUILD FAILED (total time: 6 seconds)
Does anybody have any idea about this error?
Could it be somehow related to Ant ?
What do the following lines mean?
The following error occurred while executing this line:
D:\Soft\javafx-samples-2.1.0\src\DataApp\DataAppClient\build.xml:48: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:application
Cause: The name is undefined.
Thank you!
Update:
Aparently the problem is solved by manually modifying the Ant build.xml file located in the DataAppClient project root.
I added a taskdef tag at the beginning of the -post-jar target definition and the error was gone:
...
<target name="-post-jar" depends="-init-javafx, -jfx-copylibs">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath="d:\Soft\javafx_sdk_2.1\lib\ant-javafx.jar" />
<!-- Move preloader out of libs -->
<move file="${dist.dir}/lib/DataAppPreloader.jar" todir="${dist.dir}"/>
...
Can this be an error in the official release of this sample application, or something is wrong with my setup ?
Aparently the problem is solved by manually modifying the Ant build.xml file located in the DataAppClient project root.
I added a taskdef tag at the beginning of the -post-jar target definition and the error was gone:
...
<target name="-post-jar" depends="-init-javafx, -jfx-copylibs">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath="d:\Soft\javafx_sdk_2.1\lib\ant-javafx.jar" />
<!-- Move preloader out of libs -->
<move file="${dist.dir}/lib/DataAppPreloader.jar" todir="${dist.dir}"/>
...
Anyone who has a similar error. Try the following solution (it worked for me), I found it here https://groups.google.com/forum/#!msg/efxclipse/H-ZOVXtaK6g/5yufMqQsZBQJ
The Solution
I managed to get it to work by going to Run->External Tools_>External Tools Configurations and selecting JRE Tab. I had to change the Execution environment from 1.7 to CDC-1.0/Foundation-1.0 (jdk1.7.0_25) (and CDC-1.1 also works).
The Error-
BUILD FAILED
C:\Users\Ross\workspace\MyJavaFXApp\build\build.xml:87: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

ant -f build.xml run vs ant -f build jar

Can anyone please tell me what is the technical difference between,
1-
ant -f build.xml run
and
2-
ant -f build.xml jar
java -jar project.jar
I'm asking this because my application runs flawlessly with I run it with the number "1" command
BUT
Comes up with a whole lot of exceptions when is run as a jar file (Number 2 command set).
Any explanation for this??! I just want to know why the application responds differently to these two situations???!
Thanks
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="LMB" default="default" basedir=".">
<description>Builds, tests, and runs the project LMB.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="iDA-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
And here is the manifest file
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0-b147 (Oracle Corporation)
Class-Path: lib/beansbinding-1.2.1.jar lib/AbsoluteLayout.jar lib/appf
ramework-1.0.3.jar lib/swing-worker-1.1.jar lib/swing-layout-1.0.4.ja
r lib/commons-codec-1.4.jar lib/commons-codec-1.5.jar lib/commons-log
ging-1.1.1.jar lib/derby.jar lib/derbyLocale_cs.jar lib/derbyLocale_d
e_DE.jar lib/derbyLocale_es.jar lib/derbyLocale_fr.jar lib/derbyLocal
e_hu.jar lib/derbyLocale_it.jar lib/derbyLocale_ja_JP.jar lib/derbyLo
cale_ko_KR.jar lib/derbyLocale_pl.jar lib/derbyLocale_pt_BR.jar lib/d
erbyLocale_ru.jar lib/derbyLocale_zh_CN.jar lib/derbyLocale_zh_TW.jar
lib/derbyclient.jar lib/derbynet.jar lib/derbyrun.jar lib/derbytools
.jar lib/httpclient-4.1.2.jar lib/httpclient-cache-4.1.2.jar lib/http
core-4.1.2.jar lib/httpmime-4.1.2.jar lib/jdom.jar lib/orangevolt-ant
-tasks-1.3.8.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: lmb.LMBApp
NOTE:
Here I FOUND THE SOURCE OF THIS ISSUE BUT I DON'T KNOW HOW TO FIX IT,
Everything about library referencing and environment variables are ok except the fact that I'm not getting my SSL connection to the server while launching the jar file whereas the connection is easily made while running the application from inside Netbeans. In fact I'm getting this following Exception when executing through the final jar fine,
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source)
PLEASE HELP ME WITH THIS
Likely the first one uses a compilation (or execution) classpath, while the second one relies on an environment classpath (the jar doesn't include all your app's dependencies).
All of the items in your manifest need to be added to the classpath call.
This may contain a list of dependency jars which you could include on the command line using the -classpath options
java -cp gen/jars/test.jar -jar project.jar
You could inline the Ant build.xml and/or exceptions thrown so we can give you more information.

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

Categories

Resources