import org.appfuse.webapp.action.BaseAction cannot resolve - java

i was following the guide http://appfuse.org/display/APF/Using+Struts+2 to make a simple appfuse site, but i got an error while compiling with Maven, which is reporting org.appfuse.webapp.action.BaseAction does not exist.
I searched a lot from the google with no luck, can anyone give me a hints, appreciate for any help, idea or advise. Thankyou
both maven 2.2.1 and 3 produced same error:
using archetype: appfuse-basic-struts-archetype, v.2.1.0-M1
maven command:
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -
DarchetypeArtifactId=appfuse-basic-struts-archetype -DarchetypeVersion=2.1.0-M1
-DgroupId=com.mycompany -DartifactId=myproject
at this pt, mvn test or jetty:run-war have not raise a error.
however, when i add 2 classes (PersonActionTest and PersonAction) as below, it fail to compile
PersonActionTest: src\test\java\com\mycompany\webapp\webapp\action
package com.mycompany.webapp.action;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import org.appfuse.service.GenericManager;
import org.appfuse.tutorial.model.Person; \\this fails to compile
import org.appfuse.webapp.action.BaseActionTestCase; \\this fails to compile
import org.springframework.mock.web.MockHttpServletRequest;
public class PersonActionTest extends BaseActionTestCase {
private PersonAction action;
#Override
protected void onSetUpBeforeTransaction() throws Exception {
super.onSetUpBeforeTransaction();
action = new PersonAction();
GenericManager personManager = (GenericManager) applicationContext
.getBean("personManager");
action.setPersonManager(personManager);
// add a test person to the database
Person person = new Person();
person.setFirstName("Jack");
person.setLastName("Raible");
personManager.save(person);
}
public void testSearch() throws Exception {
assertEquals(action.list(), ActionSupport.SUCCESS);
assertTrue(action.getPersons().size() >= 1);
}
}
PersonAction: src\main\java\com\mycompany\webapp\webapp\action
package com.mycompany.webapp.action;
import org.appfuse.webapp.action.BaseAction; \\this fails to compile
import org.appfuse.tutorial.model.Person; \\this fails to compile
import org.appfuse.service.GenericManager;
import java.util.List;
public class PersonAction extends BaseAction {
private GenericManager<Person, Long> personManager;
private List persons;
public void setPersonManager(GenericManager<Person, Long> personManager) {
this.personManager = personManager;
}
public List getPersons() {
return persons;
}
public String list() {
persons = personManager.getAll();
return SUCCESS;
}
}
Error Message:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AppFuse Struts 2 Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- aspectj-maven-plugin:1.2:compile (default) # realtest ---
[ERROR] The import org.appfuse.webapp cannot be resolved
[ERROR] The import org.appfuse.tutorial cannot be resolved
[ERROR] Person cannot be resolved to a type
[ERROR] Person cannot be resolved to a type
[ERROR] personManager cannot be resolved or is not a field
[ERROR] personManager cannot be resolved
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.285s
[INFO] Finished at: Thu Oct 21 09:35:56 CST 2010
[INFO] Final Memory: 6M/27M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.2:compil
e (default) on project realtest: Compiler errors :
[ERROR] error at import org.appfuse.webapp.action.BaseAction;
[ERROR] ^^^^^^^^^^^^^^^^^
truncated as the rest of msg is similar
Thanks~
steven

I know this thread is pretty old, but I got this error several times now, therefore I want to share my solution.
I recently got this error in the following setting.
* There is project, say Util, that imports a library, e.g., dbcp
* Another project, say App, depends on Util and aspects are to be applied to that project.
* I added a new class to App, that uses a transitive dependency, e.g., the new class C implements some abstract class from dbcp. Because App depends on Util, dbcp is visible in eclipse and everything is fine. However, when I compile my project on the command line using mvn install, the aspectj plugin fails with stating that the import from dbcp could not be resolved.
* Including a direct dependency from App to dbcp solves the problem (for me).
So aspectj does not use transitive dependencies while the java compiler plugin does. Probably, the position of the new class C is not the "optimal" one, it should be moved to the Util project but that is a different issue.
Hope that helps anyone coming to this thread.

I'm not an Appfuse expert (by this, I mean that I'm not aware of all the details of changes and existing issues) but the project generated using the version 2.1.0-M1 of the archetype misses the appfuse-struts artifact (which provides o.a.w.a.BaseAction).
I tried to add it manually but then ran into some other artifact resolution issue (a transitive dependency not found) and just gave up.
However, the project you'd get using the previous version of the archetype (i.e. version 2.0.2) looks ok and my recommendation would be to use this version instead:
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes \
-DarchetypeArtifactId=appfuse-basic-struts \
-DarchetypeVersion=2.0.2 \
-DgroupId=com.mycompany \
-DartifactId=myproject

Related

The import x.x.x cannot be resolved with Maven

I have a project that exports a package for another project to import and utilize. Within Eclipse, it seems to resolve correctly. But when building with Maven, I get the following errors: The import x.x.x cannot be resolved. I've fiddled around with the manifest/ pom.xml and restarted Eclipse several times and the results are the same.
The general structure is:
com.my.company.plugin
- com.my.company.pkg
And within that manifest.mf, I have Export-Package: com.my.company.pkg
For the other plugin's manifest, I have Require-Bundle: com.my.company.pkg;resolution:=optional (I've tried taking the option portion out, but that didn't seem to matter)
And within the source for the second plugin, I have:
import com.my.company.pkg.MyClass
public class MyOtherClass implements MyClass {
Locally in Eclipse it all works fine. But when I try to build with Maven, I get the following error:
[ERROR] import com.my.company.pkg.MyClass;
[ERROR] ^^^^^^^^^^^^^^^^^^
[ERROR] The import com.my.company.pkg cannot be resolved
[ERROR] public class MyOtherClass implements MyClass {
[ERROR] ^^^^^^^
[ERROR] MyClass cannot be resolved to a type
The strange thing is that I have other imports within MyOtherClass that reference other plugins and added in the Required-Bundles. I'm guessing it's how I'm exporting the first plugin. What exactly am I missing?
---EDIT---
It seems like adding this block in the parent pom is causing it to fail. Which is odd because I thought it by setting it to ignore it will completely ignore the optional dependencies instead of trying to resolve it? While taking it out causes other areas that uses optional dependencies to fail...
<dependency-resolution>
<optionalDependencies>ignore</optionalDependencies>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.ui</id>
<versionRange>0.0.0</versionRange>
</requirement>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.ui.views</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>

Maven build failure: "error while writing test: could not create parent directories"

When trying to run mvn test on Windows, my tests run fine, but on CentOS 7 I get this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.403s
[INFO] Finished at: Mon Jan 27 10:54:06 CET 2020
[INFO] Final Memory: 17M/119M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project GenericTests: Compilation failure
[ERROR] /home/gitlab-runner/builds/5KQvSgfo/0/webdriver_projects/webdriver_bv/test_dir/src/test/java/genericTests/Contact/InputMaxLengthTest.java:[18,7] error: error while writing InputMaxLengthTest: could not create parent directories
This happens with a few other tests too, although not all of them. I don't understand why. These tests don't interact with folders and in fact aren't particularly different from any other test.
The only file system interaction I have is that I take screenshots and place them in a folder, using org.apache.commons.io.FileUtils, but I have permissions on that folder. And it happens even when I comment out the file writing instructions so I don't know if it's that.
On top of adding a screenshot feature, I've since changed my pom.xml to have
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
and I have to point to the JDK 13 location via export JAVA_HOME=/usr/java/jdk-13.0.2 before running mvn. It must be either of those things. What could be the cause? Consider that this works just fine on Windows.
I've tried:
deleting the screenshot instruction (didn't work)
changing the compiler source/target to 8, as it was before (didn't work)
I didn't want to try to delete the culprit tests one by one to see if all tests had this problem or not as that would be time consuming.
EDIT: I also ran dos2unix in every file of the project, but the result is the same.
Here's the line where I take a screenshot and write to a file, done in every single test:
#After
public void tearDown() throws Exception {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
if (OSChecker.isWindows()) {
FileUtils.copyFile(scrFile, new File("screenshots\\" + formatScreenshotFilename()));
}
else {
FileUtils.copyFile(scrFile, new File("screenshots/" + formatScreenshotFilename()));
}
}
You should upgrade your configuration to use most recent version 3.8.1 of maven-compiler-plugin cause you are using a very old version.

Compilation error in compiling Protobufs in Java using SBT build tool

I am using the Play framework (which uses SBT build tool) with Java where I need to consume a Protobuf. So I have xxx.proto file. I got binary protoc compiler and added to class path. so I see -
protoc --version
libprotoc 3.1.0
I have compiled the xxx.proto file using -
protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/xxx.proto so it has generated xxx.java file.
Now when I am compiling this xxx.java file ( the project using sbt build tool)
[error] /my_project/app/helpers/xxx.java:7: package com.google.protobuf does not exist
[error] com.google.protobuf.ExtensionRegistryLite
[error] /my_project/app/helpers/xxx.java:11: package com.google.protobuf does not exist
[error] com.google.protobuf.ExtensionRegistry
[error] /my_project/app/helpers/xxx.java:6182: package com.google.protobuf.Descriptors does not exist
[error] com.google.protobuf.Descriptors.Descriptor
[error] /my_project/app/helpers/xxx.java:6185: package com.google.protobuf.GeneratedMessageV3 does not exist
[error] com.google.protobuf.GeneratedMessageV3.FieldAccessorTable`
I see in my installed library - com.google.protobuf jar is there.
My xxx.proto looks following -
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: xxx.proto
public final class xxx {
private xxx() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
......
Is there anything I have missed while generating the xxx.java file?
How should I fix these compilation error?
You need to make sure that you're using the exact same versions of protoc and libprotobuf.jar. From what you wrote, it sounds like you're using protoc version 3.1.0 but libprotobuf 2.5.0. You need to use libprotobuf 3.1.0 instead, otherwise you will get compile errors like the ones you quote.
Re-stating Kenton's answer with some more instructions:
In Intellij, click on External Libraries and find the jar for protobuf.
Check the version of protoc:
If they don't match, (as shown above) then you will get the compilation errors.
I've seen similar issue with maven after changing some field type in my proto schema and then building without doing a clean first. However, doing a clean and build fixed it every time.

Error: Class in different directory than declared

I am working in Rational Clear case.
When I import maven project in my local system fom clear case and install, it installs successfully and all the java classes are compiling.
When I try to work directly from clear case in Eclipse, and I try to install the same project, I get error in compiling all the java classes.
Few lines of Error:
Error building bundle <groupId>:<artifactId>:bundle:2.1.6 : Class in different directory than declared. Path from class name is services/helper/impl/DefaultDroolsHelper.class but the path in the jar is services/helper/impl/defaultdroolshelper.class from Jar:dot
[ERROR] Error building bundle <groupId>:<artifactId>:bundle:2.1.6 : Class in different directory than declared. Path from class name is services/helper/impl/DefaultDroolsHelperFactory.class but the path in the jar is services/helper/impl/defaultdroolshelperfactory.class from Jar:dot
[ERROR] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.422s
[INFO] Finished at: Mon Sep 08 04:23:29 EDT 2014
[INFO] Final Memory: 15M/49M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.4:bundle (default-bundle) on project wss-services: Error(s) found in bundle configuration -> [Help 1]
After installation, in target folder, the two list are generated:
createdfiles.lst
entities\output\clientenrichmenttype$clienttrader.class
entities\output\dateadjustmenttype.class
entities\dtcc\valuation\output\collateralizedtype.class
entities\triresolve\output\objectfactory.class
But inputfiles.lst:
entities\dtcc\leireplay\output\SecoryAssetClassType.java
entities\dtcc\valuation\output\VerificationType.java
entities\dtcc\leireplay\output\package-info.java
entities\output\BlockTradeOrAllocationLegType.java
Please try to resolve this issue.
Thanks,
Ravish
The file name on Windows was created in small letters evidently, though the class name is mixed-case. This works because Windows makes no distinction.
However ported to Linux or OSX, or packed in zip format as .jar/.ear/.war one has a problem.
Correcting the file name is a bit hairy; rename it to something else, and then rename it correctly. Furthermore your versions control system may hickup too.
Made a small utility CheckJavaFiles correcting wrong case of java files under Windows.
Package names it does not check. But too much effort for something maybe unneeded; they general are small letters.

Jenkins not showing maven compiler errors

When building our multi-module maven 3 project in Jenkins, if there's a build error we get this cryptic message that the maven compiler plugin failed. This only just started happening within the last week:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11:22.340s
[INFO] Finished at: Fri Feb 10 09:44:02 CET 2012
[INFO] Final Memory: 171M/318M
[INFO] ------------------------------------------------------------------------
mavenExecutionResult exceptions not empty
message : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project me.activity.impl: Compilation failure
cause : Compilation failure
Stack trace :
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project me.activity.impl: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:79)
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:585)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:158)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:104)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:70)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:287)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
at java.util.concurrent.FutureTask.run(FutureTask.java:123)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 27 more
Maven schlug mit Fehlern fehl.
An attempt to send an e-mail to empty list of recipients, ignored.
When building from the command-line we get the normal build errors:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5:24.906s
[INFO] Finished at: Fri Feb 10 08:17:31 EST 2012
[INFO] Final Memory: 173M/328M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project me.activity.impl: Compilation failure: Compilation failure:
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[1018,12] cannot find symbol
[ERROR] symbol : class ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[200,16] cannot find symbol
[ERROR] symbol : class ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[234,16] cannot find symbol
[ERROR] symbol : class ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[263,16] cannot find symbol
[ERROR] symbol : class ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[294,20] cannot find symbol
[ERROR] symbol : class ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[311,16] cannot find symbol
[ERROR] symbol : class ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[1023,47] cannot find symbol
[ERROR] symbol : variable ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] \p4views\VM\Base\main\modules\activity\impl\src\main\java\com\sap\me\activity\impl\ExtensionConfigurationService.java:[1025,67] cannot find symbol
[ERROR] symbol : variable ActivityRuntimeType
[ERROR] location: class com.sap.me.activity.impl.ExtensionConfigurationService
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :me.activity.impl
We're using maven-3.0.4 both for local builds and on Jenkins. Jenkins version was 1.3ish, but I upgraded to 1.450 to see if the issue would go away - it didn't. This happened about the time we moved from maven-2.2.1 to maven-3.0.4, but I could swear (although I don't have evidence) that I was getting normal build errors on Jenkins just after the maven upgrade, so I don't think that's it, but it's the only change I can think of that would cause this. The compiler plugin version is 2.0.2.
I saw a similar posting here but his issue had to do with eclipse builds, not Jenkins.
Got an answer, which may not work for you as it seems rather dependent on many things and circumstances, BUT I suspect it is indeed relevant for most people here.
Troubleshooting
(Skip if you don't care about how I figured this out for my setting, but it may help for yours. The Solution 1 bit is what you want if you're impatient.)
How it Started...
Current working-directory of an actively developed project started to spit out logs showing this behavior today, when there had been no errors for a while. I was using Windows 7, Maven 3.0.4, compiler plugin 2.4, and java(c) 1.6.0_31.
When reaching a specific sub-module, maven would spit out some error messages and fail the build, except the error messages were unrelated (reporting use of proprietary com.sun.* APIs) and there would be no sign of an actual compilation error.
Things get Weird...
At this point I find this thread, and I also try to re-build with different java versions and maven-compiler-plugin versions. Here's the fun part:
with compiler-plugin 2.5, I'd get a similar issue, and no valid error report;
with compiler plugin 2.3, I'd get a similar issue with a nonsensical error report complaining about a missing package (that is present and on classpath, though!);
with compiler plugin 2.3.2, I'd get a similar issue with a nonsensical error report complaining about a missing package (that is present and on classpath, though!) BUT ** at a different point **in the test-classes' compilation of the module (previously it happened during the normal classes' compilation).
From Weird to Weirder
Getting suspicious, I switched to another directory with a clean checkout of the project and re-built everything.
Everything worked FINE. Puzzlement and despair here.
So I realized I was working on a rather huge and complex class in the other workspace, in the faulty module. And I do mean rather huge, complex, and fairly poorly written. The type of beast that makes you tell your boss "please don't make me touch this" and that makes your DELETE key tickle you every time you have the misfortune of running across it in your IDE. In fact, this thing looks so much like the offspring of a dark margic experiment and weirdly unethical bioresearch that you wonder if it didn't come right out of RTC Wolfenstein or Doom, if the antagonists were bits of code. The class you don't want to be left alone to code on at night, and for which Sonar quietly reports close to 1000 code quality violations, including complexity indexes that make you wonder if PMD, JDepend and other tools are not actually all having a stroke at the same time).
But I digress...
I copied it over to this clean and seemingly working workspace (luckily for me, it didn't impact other files, so it was rather simple to do: just copy over).
Then I rebuild with Maven and it gets all cranky when it reaches the module containing this file again, except this time it prints out a load of errors a stacktrace that nevers ends. So I want to try to re-run the same build, this time saving the output to a log file to have a closer look and (here's the new odd thing, because so far that wasn't bizarre enough) ... it again doesn't show any error.
So, I'm figuring something is obviously very nasty, for javac to go belly up with what looks like a stack overflow, and look for the bit of stacktrace I could see in my log the first time around. Here's a chunk of it (as I suspect some may come across this and find this answer useful):
[ERROR] at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
[ERROR] at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:377)
[ERROR] at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1241)
[ERROR] at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1210)
[ERROR] at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
[ERROR] at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1799)
[ERROR] at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1522)
[ERROR] at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
[ERROR] at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:377)
[ERROR] at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1241)
[ERROR] at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1210)
[ERROR] at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
[ERROR] at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1799)
[ERROR] at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1522)
And Google nicely points me to... StackOverflow, of course :)
Maven compilation: Failure executing javac
Where I can see an easy thing to try (see below).
Of course, this would have been way easier to troubleshoot, had the stacktrace appeared in all situations and in all cases, and shown the obvious StackOverflowException. Especially considering I have otherwise already seen this error and know what it means, but it's a hell of a lot harder to figure out when you **can't see* the error.
Not sure why Maven swallowed that one, but maybe javac simply crashed without notice and there's a screw-up in the log management and it doesn't get flushed out properly.
That would also explain why this bug happens relatively randomly: it would be impact by your hardware settings, and slight changes to the classes javac is given to process.
So, now what??? Well, if there's a crazy stack overflow exception or an OutOfMemoryException when java tries to process your code, obviously you need to do something akin to what's explained below...
Solutions
Solution 1 (aka "short-term / quick-n-dirty / please-make-it-work")
Upgrade your memory settings. Simplest way is with something like (for a bash-like shell):
export MAVEN_OPTS="-Xss1024k -Xms512m -Xmx1024m"
BEWARE: These settings will depend on your platform's hardware, obviously (and on your shell).
In my case, I actually used to have:
export MAVEN_OPTS="-Xss128k -Xms384m -Xmx384m"
... because I have a pretty heavy project and a not so memory-capable workstation, so I need to squeeze every bit of RAM I can out of it to have multiple Eclipse instances running, multiple application servers, etc... So my JAVA_OPTS, ANT_OPTS and MAVEN_OPTS are set with a bunch of options, including these.
This is not necessarily what you want!! The default xss for a 64 bits JVM on Windows is actually 1024, so I use something considerably smaller. I'm just saying it as it may help others in the same situation. Try to raise it accordingly and sensibly for you configuration.
So, eventually, to fix this particular issue in my project, I had to change the above to:
export MAVEN_OPTS="-Xss256k -Xms384m -Xmx384m"
And now everything works peachy.
Maybe some other things are different for you. Let me know.
Solution 2 (aka "long-term / zen")
You know what's better than fiddling with memory settings that others won't know to fiddle with and may not have the chance to, and that make your builds less portable? [audience screams here]
You refactor the hell out of that butt-ugly class that makes javac cry for its mommy.
It's that simple. No thousands and thousands of lines long classes, with crazy static initializers, super long methods and stuff like these. If your code looks complicated to you, it sure does for poor javac as well.
Save a javac process today: refactor your code!!
The maven compiler plugin version I use is 2.3.2. From the output below you can see that I am getting errors as you would expect.
07:16:37 [INFO] Copying 0 resource
07:16:37 [INFO]
07:16:37 [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # fusion-common ---
07:16:38 [INFO] Compiling 49 source files to /opt/jss/hudson/work/jobs/FMWJavaCommon/workspace/target/classes
07:16:42 [INFO] -------------------------------------------------------------
07:16:42 mojoFailed org.apache.maven.plugins:maven-compiler-plugin:2.3.2(default-compile)
07:16:42 [ERROR] COMPILATION ERROR :
07:16:42 [INFO] -------------------------------------------------------------
07:16:42 [ERROR] /opt/jss/hudson/work/jobs/FMWJavaCommon/workspace/src/main/java/au/gov/qld/jag/jss/fusion/services/InvokeAuditLoggerService.java:[107,8] cannot find symbol
07:16:42 symbol : method setGeneratedTimestamp(javax.xml.datatype.XMLGregorianCalendar)
07:16:42 location: class au.gov.qld.jag.jss.fusion.services.client.auditservice.AuditLogType
07:16:42 [INFO] 1 error
0
The pom configuration for the plugin is
<!-- Compiler Version to use for Compiling Java Code -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
There are no other special configurations. I am using Hudson 2.2.0-BETA and the Hudson::Maven (legacy) plugin 2.2.0-BETA.
Not sure if this will fix your problem but I had the exact same issue because a parent pom had a plugin definition for the compiler plugin. I copied the same plugin definition to the actual project pom. This fixes the problem for me, i.e. Jenkins is now showing the compiler errors properly. Not sure why this fixed the problem but it does. Maybe it has something to do with the fact that maven forks a process to compile sub-modules and that terminal is not piped to the jenkins console. I will explore more when I get time.
Let me know if this works for you. I have copied my plugin definition below its fairly standard:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
You should check where the class ActivityRuntimeType is located. Most likely it's not on the compiler's build or class path. This usually happens when a class you depend on is in a dependency that changes unexpectedly.

Categories