BUILD FAILED apache-tomcat-7.0.42-src build.xml - java

I have both JAVA_HOME and ANT_HOME set:
damechen#ubuntu:~/apache-tomcat-7.0.42-src$ echo $ANT_HOME
/home/damechen/tmp/damechen/apache-ant-1.9.1
damechen#ubuntu:~/apache-tomcat-7.0.42-src$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.7.0.25
damechen#ubuntu:~/apache-tomcat-7.0.42-src$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
I was trying to use ant to build tomcat, but it failed for some reasons related to build.xml.
BUILD FAILED
/home/damechen/apache-tomcat-7.0.42-src/build.xml:2396: The following error occurred while executing this line:
/home/damechen/apache-tomcat-7.0.42-src/build.xml:2625: Directory /usr/share/java/tomcat-native-1.1.27 creation was not successful for an unknown reason
at org.apache.tools.ant.taskdefs.Mkdir.execute(Mkdir.java:70)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:1393)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440)
at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
damechen#ubuntu:~/apache-tomcat-7.0.42-src$
Anyone can kindly give me a hand? Thanks a lot!

As the exceptions says. The built failed while it was trying to create a directory by the name tomcat-native-1.1.27 in /usr/share/java/.
Please give proper rights.

You need to read the build instructions for Apache tomcat:
http://svn.apache.org/repos/asf/tomcat/tc7.0.x/tags/TOMCAT_7_0_42/BUILDING.txt
(3.2) Building
The build is controlled by creating a ${tomcat.source}/build.properties
file.
It is recommended to always create the file, because of unfortunate
default value of base.path property. You may start with the following
content for the file:
# ----- Default Base Path for Dependent Packages -----
# Replace this path with the directory path where dependencies binaries
# should be downloaded
base.path=/home/me/some-place-to-download-to
Configure base.path property by adding it to the
${tomcat.source}/build.properties file.
The base.path property specifies the place where Tomcat dependencies
required by the build are downloaded. It is recommended to place this
directory outside of the source tree, so that you do not waste your
time re-downloading the libraries.
WARNING: The default value of base.path property makes the build script
to download libraries required to build Tomcat to the /usr/share/java
directory. On a typical Linux or MacOX system an ordinary user will not
have access to write to this directory. Even if you do have access to
that directory, it is likely not appropriate for you to write there.
Note the warning at the end.... This is the root cause of your issue.
Analysis
The build file is calling the "download-2" target when it fails:
<target name="extras-commons-logging-prepare"
depends="extras-prepare"
description="Prepare to build web services extras package">
<antcall target="downloadfile-2">
<param name="sourcefile.1" value="${commons-logging-src.loc.1}"/>
<param name="sourcefile.2" value="${commons-logging-src.loc.2}"/>
<param name="destfile" value="${commons-logging-src.tar.gz}"/>
<param name="destdir" value="${commons-logging.home}"/>
</antcall>
..
..
In your build.properties file you have set the value of the commons-logging.home property to a directory path for which you do not have permissions to create a directory namely:
/usr/share/java/...
Digging further I see that default properties file sets this path as follows:
# ----- Default Base Path for Dependent Packages -----
# Please note this path must be absolute, not relative,
# as it is referenced with different working directory
# contexts by the various build scripts.
base.path=/usr/share/java
#base.path=C:/path/to/the/repository
#base.path=/usr/local
..
..
commons-logging.version=1.1.1
commons-logging.home=${base.path}/commons-logging-${commons-logging.version}

Related

SonarQube 5.6.1 throwing bad major version while compiling a Java 7 project with Ant

I have a Jenkins job that uses Ant to build a project.
The project is in Java 7. The runtime for the Jenkins job is also Java 7. I'm using SonarQube 5.6.1 which runs on Java 8. SonarQube server is running fine.
However, when it's time to invoke the <sonar:sonar /> target in Ant, I get the following error which clearly is due to a Java version mismatch (JVMCFRE003 bad major version). I am not sure how to solve this.
sonar:
parsing buildfile jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml from a zip file
parsing buildfile jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml from a zip file
[available] Found: /var/lib/jenkins/slave/workspace/Build/Component/Build-subcomponent/builds/com.mycompany.myproj.bootstrap.site/compile
parsing buildfile jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml from a zip file
[sonar:sonar] Apache Ant(TM) version 1.9.7 compiled on April 9 2016
[sonar:sonar] SonarQube Ant Task version: 2.2
[sonar:sonar] Loaded from: file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar
[sonar:sonar] INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
[sonar:sonar] INFO: Work directory: /var/lib/jenkins/slave/workspace/Build/Component/Build-subcomponent/com.mycompany.myproj.bootstrap.site/../builds/com.mycompany.myproj.bootstrap.site/sonar
[sonar:sonar] INFO: SonarQube Server 5.6.1
BUILD FAILED
/var/lib/jenkins/slave/workspace/Build/Component/Build-subcomponent/build/common.xml:229: java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/sonar/api/utils/SonarException, offset=6
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:324)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:155)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:712)
at java.net.URLClassLoader.access$400(URLClassLoader.java:93)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1164)
at java.security.AccessController.doPrivileged(AccessController.java:492)
at java.net.URLClassLoader.findClass(URLClassLoader.java:595)
at org.sonar.runner.impl.IsolatedClassloader.loadClass(IsolatedClassloader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:731)
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.prepare(J9VMInternals.java:514)
at java.lang.Class.getMethod(Class.java:1116)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:85)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(AccessController.java:400)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:53)
at org.sonar.ant.SonarTask.execute(SonarTask.java:48)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
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.taskdefs.Sequential.execute(Sequential.java:68)
at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:155)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
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.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:854)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
The problem is that we're talking about a Jenkins job, and the version of Java used for the job will be used for each step in the job. Since you're running the job with Java 7, the analysis is also running with Java 7 & that's not compatible with SonarQube 5.6+.
The easiest thing to do is move analysis from the Ant script into a SonarQube Scanner Build Step; it will let you choose a different Java version from the one running the job.
Alternately you could maybe accomplish this with a pipeline
node() {
def jdk8 = tool 'jdk-8u45'
def jdk7 = tool 'jdk-7u70'
withEnv(["PATH+JDK7=${jdk7}/bin"]) {
sh 'ant [normal target here]'
}
withEnv(["PATH+JDK8=${jdk8}/bin"]) {
sh 'ant [analysis target here]'
}
}
Your third option would be to split the job in 2 and use a shared workspace (Configure > Project Options > Advanced > Use custom workspace)

Ant class path error when programmatically building Netbeans platform application

I want to run a Netbeans 7.3 platform application (let's name it app A) from another Java application (app B). To do this, in B's code I'm invoking the Ant library as follows:
Path pathA = ... // where the A's sources are
Path fileBuild = pathA.resolve("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", fileBuild.toFile().getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.setDefault("run");
p.executeTarget(p.getDefaultTarget());
Unfortunately, the error I'm getting is:
C:\Program Files\NetBeans 7.3\harness\suite.xml:184: The following error occurred while executing this line:
C:\Program Files\NetBeans 7.3\harness\common.xml:217: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files (x86)\Java\jdk1.7.0_45\jre"
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:568)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:443)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:221)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
...
The JAVA_HOME variable is set correctly both as system path variable and in netbeans config file and points to C:\Program Files (x86)\Java\jdk1.7.0_45.
The question is, what am I missing? When running the app A from Netbeans menu, everything runs fine, so what should I append to the build file/ant settings to achieve A runs from B's code execution?
Thanks in advance!
Edit: I managed to get a more precise error stack, maybe this can help.
Error on test cases execution.
C:\Program Files\NetBeans 7.3\harness\common.xml:217: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files (x86)\Java\jdk1.7.0_45\jre"
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:130)
at org.apache.tools.ant.taskdefs.Javac.findSupportedFileExtensions(Javac.java:984)
at org.apache.tools.ant.taskdefs.Javac.scanDir(Javac.java:961)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:932)
at org.netbeans.nbbuild.CustomJavac.execute(CustomJavac.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at odoetest.server.ServerInvokerAnt.start(ServerInvokerAnt.java:48)
at odoetest.EntryPoint.invokeTests(EntryPoint.java:58)
at odoetest.EntryPoint.main(EntryPoint.java:38)
Edit-2: I don't have any separate ant installation and use the ant delivered with Netbeans. When I run ant -diagnostics, I get this info. When I invoke the build or run job from the command line like
ant -f /path/to/build.xml run
no errors are thrown, the program starts. I just can't do the exact same thing from java code from above.
Your Ant build.xml will still be referring to a JRE rather than the JDK.
Right-click on your project, select Libraries, check that Java Platform points to a JDK rather than a JRE. See here for details.
If this fails:
You can explicitly set properties for Project p
as in manouti's answer above. This will ensure that Project p as well as Project A will be referring to a JDK rather than JRE. AFAIK, no need to fork.
You can set properties in your .properties file, though it is not always easy to debug whether this is being implemented for each project.
You can explicitly include folders/files on the classpath of your target using the <classpath> element - see the Apache Ant Manual for some not very clear documentation.
This would be:
<classpath>
<pathelement path="${path.to.jdk}"/>
</classpath>
See also this answer.
NetBeans has setting which java to use internally. It's part of the netbeans.conf file. You are able to set the Java version for every NetBeans project which might be different.
However your JAVA_HOME points to a JRE and not JDK. That's why it cannot find the compiler - javac.
The error is occurring when calling the Ant javac task. Try to locate the call to that task (it should be in common.xml at the line shown in the error message), and try adding fork="yes" to it so that it runs the JDK compiler in an external process. See http://ant.apache.org/manual/Tasks/javac.html:
<javac fork="yes" ...
Also try adding the following property in the project invocation:
Project p = new Project();
p.setUserProperty("ant.file", fileBuild.toFile().getAbsolutePath());
p.setProperty("java.home", "C:\\Program Files (x86)\\Java\\jdk1.7.0_45");

Gradle JRE vs JDK please add lib/tools.jar from your JDK

I'm running java tests with gradle.
here is the exception I have:
java.lang.RuntimeException: java.lang.IllegalStateException: Unable to load Java agent; please add lib/tools.jar from your JDK to the classpath
at org.powermock.modules.agent.PowerMockClassRedefiner.redefine(PowerMockClassRedefiner.java:59)
at org.powermock.modules.agent.support.PowerMockAgentTestInitializer.redefine(PowerMockAgentTestInitializer.java:49)
at org.powermock.modules.agent.support.PowerMockAgentTestInitializer.initialize(PowerMockAgentTestInitializer.java:41)
at com.blablacompany.app.weight.WeightMilestonesViewBeanUnitTest.setUpMock(WeightMilestonesViewBeanUnitTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unable to load Java agent; please add lib/tools.jar from your JDK to the classpath
at org.powermock.modules.agent.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:97)
at org.powermock.modules.agent.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:70)
at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:40)
at org.powermock.modules.agent.PowerMockAgent.verifyInitialization(PowerMockAgent.java:83)
at org.powermock.modules.agent.PowerMockAgent.instrumentation(PowerMockAgent.java:76)
at org.powermock.modules.agent.PowerMockClassRedefiner.redefine(PowerMockClassRedefiner.java:57)
... 37 more
It turns out that for some reason my gradle uses JRE's folder as java.home and this is why it can not find the tools.jar.
I on't think that I want manually add it to my classpath though. I'm wondering if there any way to tell gradle to use JDK's java home instead of JRE's?
I also tried overriding it using org.gradle.java.home in gradle.properties file and it did not work. Any help is greatly appreciated.
WHen I run the same tests from my IDE(Intellij IDEA) all tests are passed successfully. I'm running all it on Mac OS.
println System.getenv("JAVA_HOME")
println System.properties['java.home']
displays:
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre
It's not a JDK vs. JRE problem. The values of JAVA_HOME vs. java.home are correct and expected (see other SO question on this topic). tools.jar is necessary to execute tools such as javac and javadoc. However, neither the JDK's javac command line compiler nor Gradle's JavaCompile task will automatically put tools.jar on the compile class path of user code. Instead you'll have to add it explicitly. For example:
def jdkHome = System.getenv("JAVA_HOME")
dependencies {
compile files("$jdkHome/lib/tools.jar")
}
Ok, seems that JRE is actually the right one that I need to use. No reason java.home to be set to JDK.
So the way I solved it was just adding tools library to my classpath:
testCompile ([fileTree(dir: "${System.properties['java.home']}/../lib", include: '*tools.jar'),fileTree(dir: "lib/test", include: '*.jar') ])
Initially the reason why I did not wanted to do this was that once I added it I had a bunch of
java 7 errors: java.lang.VerifyError: Expecting a stackmap frame at branch target 10
I did fix it by adding "-noverify" parameter to my tests closure:
Closure basicTestConfiguration = {
jvmArgs "-Dactivemq.directory=${testActivemqDir}",
"-Duser.timezone=Etc/UTC",
"-javaagent:${configurations.testAgent.singleFile}",
"-XX:MaxPermSize=256m",
"-noverify"
...
}
and applying this closure to my test suite:
postCommitSuite basicTestConfiguration
Edited
Check this out http://www.gradle.org/docs/current/userguide/build_environment.html.
Especially this section
The configuration is applied in following order (in case an option is configured in multiple locations the last one wins):
from gradle.properties located in project build dir.
from gradle.properties located in gradle user home.
from system properties, e.g. when -Dsome.property is used in the command line.

can't build a ant target in TFS location

I have a ant target, xml file in my TFS project folder. the project folder is bound with TFS(Team Foundation Server). My problem is when ever i try to build the project by running the ant target in that TFS bound location it fails. it gives the following failure.
> ria_ant_build.xml:435: Error running C:\Program Files\Java\jdk1.6.0_20\bin\javac.exe compiler
at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.
java:508)
at org.apache.tools.ant.taskdefs.compilers.JavacExternal.execute(JavacExternal.java:61)
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1153)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:930)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.6.0_20\bin\javac.exe": CreateProcess erro
r=87, The parameter is incorrect
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495)
at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.
java:505)
... 19 more
Caused by: java.io.IOException: CreateProcess error=87, The parameter is incorrect
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 24 more
but when i copy the project to a different location and remove the read only attribute from the folder the ant target runs without any error and I'm getting a deploy-able artifact. but even when i remove the read only attribute from the TFS folder i could not build the ant target.It seems like the problem exist on the TFS location it self. :(
can some one suggest me a method to solve this problem. I have to stay in the TFS location you guys know the reason i assume :)
--
Thanks & Regards,
Rangana
From your question it's hard to figure out what really causes your problem.
Perhabs, your ant call length is too long and even longer than the max command prompt line (that's 8191 characters in the latest versions of Windows). As question Fail to launch application (CreateProcess error=87), can't use shorten classpath workaround says you may consider "to shorten folder names, reduce depth of folder trees, using parameter files, etc".
Try to run ant with the -debug option to see the specific command-line parameters of your build call inside the TFS workspace. In that way you can estimate the total length of the call.

JavaMail jar name causes JAF exception?

I'm running into an odd problem with a mail sending component in one of our projects. Since we switched over to using Apache Ivy to manage build dependencies, we now deploy jars named mail-1.4.4.jar instead of the previous mail.jar.
With the versioned jar, we get a stacktrace (see below). If I take that same jar and manually rename it to mail.jar, the mail is sent successfully. It seems like some sort of classpath issue with JAF unable to find the mail component classes, but I'm stumped about how to resolve the root issue instead of a band-aid solution like configuring the build to rename the jar.
Failure stacktrace:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_0_522583802.1299253374905"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1141)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at com.rbccm.core.util.MailUtil.sendMail(MailUtil.java:91)
at com.rbccm.core.util.MailUtil.sendWithAttachment(MailUtil.java:59)
at com.rbccm.core.util.MailUtil.sendWithAttachment(MailUtil.java:36)
at com.rbccm.core.util.MailTask$Command$1.execute(MailTask.java:88)
at com.rbccm.core.util.MailTask$Command$1.execute(MailTask.java:83)
at com.rbccm.core.util.BatchTask.execute(BatchTask.java:31)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_0_522583802.1299253374905"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
at javax.activation.DataHandler.writeTo(DataHandler.java:302)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1099)
... 25 more
java -version output:
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
This sounds like a class path issue. The Java Activation Framework might be set up with a class path that includes mail.jar. That would explain why it works when you rename mail-1.4.4.jar to mail.jar.
Make sure your JAF and Java Mail API jars are compatible, then update the class path appropriately.

Categories

Resources