GWT 2.8 cannot get custom linker to work - java

I have a custom linker to generate a manifest file that used to work fine up to GWT 2.7. When I changed to GWT 2.8 I noticed it stopped generating the file myapp.manifest.
On module.gwt.xml I have
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.gwt.core.Core" />
<source path="client" />
<source path="shared" />
<source path="constants" />
<entry-point class="br.com.universo.client.AppStart" />
<extend-property name="locale" values="pt" />
<extend-property name="locale" values="en" />
<set-property-fallback name="locale" value="en" />
<define-linker class="br.com.universo.AppManifest"
name="manifest" />
<add-linker name="manifest" />
</module>
This is the compilation log on 2.7
[INFO] --- gwt-maven-plugin:2.7.0:compile (default) # universo-bootstrap ---
[INFO] auto discovered modules [br.com.universo.core.appCore, br.com.universo.app]
[INFO] br.com.universo.core.appCore has no EntryPoint - compilation skipped
[INFO] Compiling module br.com.universo.app
[INFO] Ignored 7 units with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO] Compiling 6 permutations
[INFO] Compiling permutation 0...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 1...
[INFO] Compiling permutation 2...
[INFO] Compiling
[INFO] Compiling permutation 3...
[INFO] Compiling permutation 4...
[INFO] Compiling permutation 5...
[INFO] Compile of permutations succeeded
[INFO] Compilation succeeded -- 165.867s
[INFO] MyApp OffLine Linker started
[INFO] MyApp OffLine Linker ended
[INFO] Linking into /universo/universo-bootstrap/target/universo-bootstrap-1.0-SNAPSHOT/app
[INFO] Link succeeded
[INFO] Linking succeeded -- 1.239s
On GWT 2.8 I am using tbroyer gwt maven archetype modular-webapp. The linker class was defined under the client module, but on a package outside
<source path="client" />
and on compilation log I don't see the lines:
[INFO] MyApp OffLine Linker started
[INFO] MyApp OffLine Linker ended
which I suppose indicates it is not being called?
[INFO] --- gwt-maven-plugin:1.0-rc-7:compile (default-compile) # universo-client ---
[INFO] Compiling module br.com.universo.app
[INFO] Compiling 9 permutations
[INFO] Compiling permutation 0...
[INFO] [WARN] Namespace option is not compatible with CodeSplitter, turning it off.
[INFO] Compiling permutation 1...
[INFO] Compiling permutation 2...
[INFO] Compiling permutation 3...
[INFO] Compiling permutation 4...
[INFO] Compiling permutation 5...
[INFO] Compiling permutation 6...
[INFO] Compiling permutation 7...
[INFO] Compiling permutation 8...
[INFO] Compile of permutations succeeded
[INFO] Compilation succeeded -- 104.171s
[INFO] Linking into /universo/universo-client/target/universo-client-1.0-SNAPSHOT/app
[INFO] Link succeeded
[INFO] Linking succeeded -- 1.818s
The Linker class AppManifest.java
package br.com.universo;
import java.util.Date;
import com.google.gwt.core.ext.LinkerContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.AbstractLinker;
import com.google.gwt.core.ext.linker.ArtifactSet;
import com.google.gwt.core.ext.linker.EmittedArtifact;
import com.google.gwt.core.ext.linker.LinkerOrder;
import com.google.gwt.core.ext.linker.LinkerOrder.Order;
import com.google.gwt.core.ext.linker.Shardable;
#Shardable
#LinkerOrder(Order.POST)
public class AppManifest extends AbstractLinker {
static final String[] cache = new String[] {
"# Css"
, "/css/base.css"
, "/css/feedback.css"
, "/css/layout.css"
, "/css/prettyPhoto.css"
, "/css/shortcodes.css"
, "/css/slideshow.css"
, "/css/style.css"
};
static final String[] network = new String[] {
"*"
};
#Override
public String getDescription() {
return "MyApp OffLine Linker";
}
#Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException {
System.out.println("MyApp OffLine Linker started");
ArtifactSet artifactset = new ArtifactSet(artifacts);
StringBuilder builder= new StringBuilder("CACHE MANIFEST\n");
builder.append("# Cache Version " + new Date() + "\n\n");
builder.append("CACHE:\n");
for (String line : cache) {
builder.append(line + "\n");
}
builder.append("\n\n");
for(EmittedArtifact emitted: artifacts.find(EmittedArtifact.class))
{
if(emitted.getPartialPath().endsWith(".symbolMap"))continue;
if(emitted.getPartialPath().endsWith(".txt"))continue;
builder.append(emitted.getPartialPath()).append("\n");
}
builder.append("\n\n");
builder.append("NETWORK:\n");
for (String line : network) {
builder.append(line + "\n");
}
builder.append("\n\n");
builder.append("FALLBACK:\n");
EmittedArtifact manifest = emitString(logger, builder.toString(), "myapp.manifest");
artifactset.add(manifest);
System.out.println("MyApp OffLine Linker ended");
return artifactset;
}
}
Any help is well appreciated!

I finally had it working changing my AppManifast.java. I noticed on current documentation that when using #Shardable annotation you have to override the other link method signature, so I added the following lines to the class:
#Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException {
return link(logger, context, artifacts);
}
It took me forever to find out...

Related

Eclipse jdk 11 problem: The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

I have a toy program that has a compilation error only in Eclipse when I try to use a Chronicle import and compile to language level 11. The program compiles and runs in maven, and also in IntelliJ (with the same maven and JDK).
The versions I have are:
maven 3.6.1
jdk openjdk version "11" 2018-09-25
eclipse 2020-03-R
chronicle-bom 2.19.199 (supported java11 since 2.17)
This is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testjava11</groupId>
<artifactId>chronicle-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>2.19.199</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
</dependency>
</dependencies>
</project>
And here is my simple test class:
import net.openhft.chronicle.bytes.BytesMarshallable;
public class App {
public static void main(String[] args) {
System.out.println("BytesMarshallable: " + new BytesMarshallable() {});
}
}
The output when running exec:java directly with maven is
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< testjava11:chronicle-test >----------------------
[INFO] Building chronicle-test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # chronicle-test ---
[INFO] Deleting C:\Users\eclipse-workspace\chronicle-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # chronicle-test ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # chronicle-test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\eclipse-workspace\chronicle-test\target\classes
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) # chronicle-test ---
BytesMarshallable: App$1#309d6b5b
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.400 s
[INFO] Finished at: 2020-06-11T15:04:53+02:00
[INFO] ------------------------------------------------------------------------
It compiles in IntelliJ and this is the output when I run as a Java Application:
BytesMarshallable: App$1#39fb3ab6
Process finished with exit code 0
However, in Eclipse the class App will not compile. The error is on the import line and says:
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
There is an additional message in the Problems panel:
The project was not built since its build path is incomplete.
Cannot find the class file for java.lang.String.
Fix the build path then try building this project
But I don't see what the issue is in my build path:
Furthermore, I can see java.lang is present in the package explorer:
(Note that if I change the language level to 8, but still using JDK 11, it will work in Eclipse.)
I have checked for obvious issues (build path, maven/jdk path) and everything appears correct to me. Why do I get this error in Eclipse and how can I fix it?
The full error message is :
Type java.lang.String is indirectly referenced from required .class files but cannot be resolved since the declaring package java.lang exported
from module java.base conflicts with a package accessible from module
It's caused by one of the transitive dependencies, net.openhft:affinity:3.2.3, embedding 2 classes from the java.lang package, which is illegal. The ECJ compiler in Eclipse complaining about it is expected. However, the fact it works in javac is a bug in itself: https://bugs.openjdk.java.net/browse/JDK-8215739
There's an affinity issue about it: https://github.com/OpenHFT/Java-Thread-Affinity/issues/58
If you're not using the thread affinity features, just exclude affinity from your dependencies and the Eclipse compiler will stop complaining.
The error was solved after I opened
Window > Preferences: Java > Installed JREs > Execution Env
And re-selected the JavaSE-11, Apply and Close
In my case I had following error, and it had no relationship with "Configure build path" --
The type java.io.FilterOutputStream cannot be resolved. It is indirectly referenced from required .class files
The error was solved after I create a package and located the problematic class into the class.
It has a mismatch with pom file so update in pom file as well.
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
I have used these two then its working fine for me.

Custom PMD Java rule violations not showing on SonarQube

I'm trying to run my custom PMD rules on SonarQube but, so far, without success.
I have created a plugin which extends from the sonar-pmd-plugin. In this plugin I have my PMD ruleset file (custom_rules.xml), a Sonar rules file (pmd-extensions.xml) and the Java classes of my custom rules.
SonarQube identifies my rules, and I have enabled them in my default quality profile. Finally, when I run the sonar analysis on a given project, I see that my custom rules are properly executed and that they find violations in the project under analysis.
However, these violations are never shown on the project dashboard on SonarQube.
The version of SonarQube I'm using is 5.1.1. The version of the PMD plugin is 2.4.1.
I created a minimal example for this issue, with only one custom rule.
custom_rules.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="My custom rules" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<rule
language="java"
name="RuleJavaAssert"
message="Avoid assert in production"
class="br.gov.tcu.rules.RuleJavaAssert">
<description>Production code should not use the assert command</description>
<priority>3</priority>
</rule>
</ruleset>
pmd-extensions.xml:
<rules>
<rule>
<key>br.gov.tcu.rules.RuleJavaAssert</key>
<name>Avoid assert in production</name>
<category name="Maintainability" />
<priority>BLOCKER</priority>
<description>Production code should not use the assert command</description>
<configKey>br/gov/tcu/rules/custom_rules.xml/RuleJavaAssert</configKey>
</rule>
</rules>
RuleJavaAssert.java:
public class RuleJavaAssert extends AbstractJavaRule {
#Override
public Object visit(ASTAssertStatement node, Object data) {
System.err.println("Found violation");
addViolation(data, node);
return super.visit(node, data);
}
}
AssertViolation.java:
public class AssertViolation {
public static void testMethod() {
String test = "test";
assert(test != null);
}
}
The output of SonarQube analysis on the console, when run against a project which contains the class "AssertViolation.java":
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building teste-pmd 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:2.7.1:sonar (default-cli) # teste-pmd ---
[INFO] User cache: D:\Users\x02315941199\.sonar\cache
[INFO] SonarQube version: 5.1.1
(...)
[INFO] [15:48:17.564] Sensor PmdSensor
[INFO] [15:48:17.564] Execute PMD 5.3.1...
[INFO] [15:48:17.580] Java version: 1.7
[INFO] [15:48:17.595] PMD configuration: D:\Users\x02315941199\Documents\PMD\workspace\teste-pmd\target\sonar\pmd.xml
Found violation
[INFO] [15:48:17.815] PMD configuration: D:\Users\x02315941199\Documents\PMD\workspace\teste-pmd\target\sonar\pmd-unit-tests.xml
[INFO] [15:48:17.815] Execute PMD 5.3.1 done: 251 ms
[INFO] [15:48:17.971] Sensor PmdSensor (done) | time=407ms
(...)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.185 s
[INFO] Finished at: 2015-11-11T15:48:19-02:00
[INFO] Final Memory: 72M/741M
[INFO] ------------------------------------------------------------------------
From the console message "Found violation" I can see that the rule was executed properly, but still SonarQube indicates 0 issues.
Any thoughts?
Thanks
The reason SonarQube doesn't show the violations is because the violation recorder in the sonar-pmd-plugin searches for the rule by its key.
Therefore, the key attribute in the pmd-extensions.xml file must equal the name attribute of the rule in custom_rules.xml
The provided example would be fixed by changing the pmd-extensions.xml content to:
<rules>
<rule>
<key>RuleJavaAssert</key>
<name>Avoid assert in production</name>
<category name="Maintainability" />
<priority>BLOCKER</priority>
<description>Production code should not use the assert command</description>
<configKey>br/gov/tcu/rules/custom_rules.xml/RuleJavaAssert</configKey>
</rule>
</rules>

maven dependency java.util.function not properly loading for function class

When I build this in maven it compiles successfully.
package com.hf.arm;
import org.apache.spark.SparkConf;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
public class App
{
public static void main( String[] args )
{
SparkConf conf = new SparkConf().setAppName("FP-growth Example");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> data = sc.textFile("/Users/lincolnsmith/Table_csv/sample_fpgrowth.txt");
}
}
I need to add a bit of code and so the new script looks like:
package com.hf.arm;
import org.apache.spark.SparkConf;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
public class App
{
public static void main( String[] args )
{
SparkConf conf = new SparkConf().setAppName("FP-growth Example");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> data = sc.textFile("/Users/lincolnsmith/Table_csv/sample_fpgrowth.txt");
JavaRDD<List<String>> transactions = data.map(
new Function<String, List<String>>() {
public List<String> call(String line) {
String[] parts = line.split(" ");
return Arrays.asList(parts);
}
}
);
FPGrowth fpg = new FPGrowth()
.setMinSupport(0.2)
.setNumPartitions(10);
FPGrowthModel<String> model = fpg.run(transactions);
for (FPGrowth.FreqItemset<String> itemset: model.freqItemsets().toJavaRDD().collect()) {
System.out.println("[" + itemset.javaItems() + "], " + itemset.freq());
}
double minConfidence = 0.8;
for (AssociationRules.Rule<String> rule
: model.generateAssociationRules(minConfidence).toJavaRDD().collect()) {
System.out.println(
rule.javaAntecedent() + " => " + rule.javaConsequent() + ", " + rule.confidence());
}
}
}
But I get this error:
"cannot find symbol symbol: class Function"
Obviously I'm missing the package java.utils.function and so I import this
import java.util.function.Function;
And I add the dependency to my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hf.arm</groupId>
<artifactId>arm</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>arm</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.10</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-backport-java.util.function</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
But now I continue to get the error output:
Lincolns-MacBook-Pro:arm lincolnsmith$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building arm 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # arm ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/lincolnsmith/Table_csv/arm/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # arm ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/lincolnsmith/Table_csv/arm/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,11] '.' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,12] ';' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,16] class, interface, or enum expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,17] class, interface, or enum expected
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.241 s
[INFO] Finished at: 2015-10-14T10:05:13-04:00
[INFO] Final Memory: 19M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project arm: Compilation failure: Compilation failure:
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,11] '.' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,12] ';' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,16] class, interface, or enum expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,17] class, interface, or enum expected
[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
I can't find a different maven source for this dependency and I've tried cleaning and emptying my.m2 directory. Is there a different dependency source for java.utils.function that I can use for maven or is something else wrong?
Here is my java version:
Lincolns-MacBook-Pro:arm lincolnsmith$ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Actually you don't need backport package as Function belong to Spark API, not to Java 8 API. Try this instead:
JavaRDD<List<String>> transactions = data.map(
new org.apache.spark.api.java.function.Function<String, List<String>>() {
public List<String> call(String line) throws Exception {
String[] parts = line.split(" ");
return Arrays.asList(parts);
}
}
);
Then you can build and run your application with correct classpath:
mvn clean compile exec:java -Dexec.mainClass="com.hf.App"
And it works pretty fine (with expected result in my case):
...
org.apache.spark.SparkException: A master URL must be set in your configuration
at org.apache.spark.SparkContext.<init>(SparkContext.scala:394)
...

What is the correct way to create a Java package from command line? (trouble with Maven)

[ SOLVED ] - but still looking for explanation. Please see bottom of question
I don't have much experience with command line or with Maven. I'm working on a tutorial from a book. It state I should create a java file
src/main/java/com/effectivemaven/chapter01/ExampleAction.java
What I did was mkdir each directory separately i.e. mkdir com, mkdir effectivemaven, mkdir chapter01
I create the .java file in the chapter01 directory.
package com.effectivemaven.chapter01;
import org.slf4j.*;
public class ExampleAction {
final Logger logger = LoggerFactory.getLogger(ExampleAction.class);
public boolean execute() {
logger.info( "Example Action Executed." );
return true;
}
}
When I mvn compile, it says compiling 1 file to target..., but when I look at the taget directory, nothing is created.
So I tried to create a another .java file without using packages, just a simple
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
in the java directory, then mvn compile and it shows up in the target file.
So my assumption is that I'm not creating the packages correctly by using mkdir, or possibly I'm doing something else wrong I'm unaware of.
So basically I just want to know, what is the correct way to create a package from the command line? And if I'm doing it correctly, what could be the other possible reasons the .class is not being created in the target?
EDIT tree
first-webapp
src
main
java
Hello.java
com
effectivemaven
chapter01
ExampleAction.java
target
classes
Hello.class
pom.xml
Command running from C:\Maven Book\first-webapp>
C:\Maven Book\first-webapp>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building first-webapp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # first-weba
pp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # first-webapp
---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 2 source files to C:\Maven Book\first-webapp\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.667s
[INFO] Finished at: Sun Jan 12 00:09:49 PST 2014
[INFO] Final Memory: 11M/111M
[INFO] ------------------------------------------------------------------------
C:\Maven Book\first-webapp>
EDIT pom.xml as requested
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.underdogdevs.webapp</groupId>
<artifactId>first-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>first-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
<build>
<finalName>first-webapp</finalName>
</build>
</project>
By the way, this is a web-app I created with the following command
mvn archetype-generate -DgroupId=com.underdogdevs.webapp -DartifactId=first-webapp -DarchetypeArtifactid=maven-archetype-webapp
[ SOLVED ] - but with very mimimal understanding - still offering brownie points for anyone who can explain to me this behavior. Below is what I did
I got it to work. Since I create the project with groupId=com.underdogdevs.webapp, I tried to make a package com\underdogdevs\webapp and created a the class with the corresponding package reference. This fixed the problem. The class appears. But I tested it even further and deleted the package I just created and tried to clean and compile with only the original package structure, but the file showed up again in the orginal package structure. I have no idea why this happens though.Anyone have any ideas?
Ok, the groupid isn't related to your application structure -- it's part of your application name. You are building a webapp, so the compiled classes go into the WEB-INF/classes directory in the generated war file (which, according to your pom is called first-webapp.war) which can be found in the target directory. You need directories src/main/java, src/main/resources, src/test/java, src/test/resources, src/main/webapp/WEB-INF. Under the java directory you should put your package structure (more directories), which in this case is com/effectivemaven/chapter01 and under that put your java file ExampleAction.java. Put your pom in your project root.
On the command line run mvn clean install and you'll generate the target and you should find your .war file in there. In that, under the WEB-INF/classes/com/effectivemavem/chapter01 directory you'll find your compiled java class with a .class extension.
At some point you'll have to put a web.xml file in the WEB-INF directory.

Maven "could not parse error message" (Java 7 + Maven 2)

I have a maven-based GWT project that includes Guava. I am running into trouble with Maven trying (and failing) to compile the sources that it finds in guava-gwt*.jar:
could not parse error message: symbol: static setCountImpl
location: class
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):100: error: cannot find symbol
return setCountImpl(this, element, count);
^
I can't figure out why Maven thinks it needs to compile the sources in guava-gwt. Here's what my project looks like:
├── pom.xml
└── src
   ├── main
   │   └── java
   └── test
   └── java
   └── SomeTestFile.java
SomeTestFile.java
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.junit.Test;
public class SomeTestFile {
#Test
public void testMethod() {
Multimap<Integer, String> someMap = ArrayListMultimap.create();
someMap.put(5, "five");
System.out.println(someMap);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>guava-problem</groupId>
<artifactId>guava-problem</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-gwt</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have already tried the following:
Removing the guava dependency (leaving only guava-gwt)
Scoping guava-gwt to provided
I'm not sure what else to try. guava-gwt includes sources because GWT will compile it into equivalent Javascript. But I don't want Maven to try to compile these sources.
Edit
Just a note...the test files themselves have no real need for guava-gwt over guava since they are compiled and run as Java code (they don't go through the GWT compile step). I don't need guava-gwt specifically for these tests but it needs to be available for my actual GWT client code.
Full Maven Output
mark#mark-peters:~/devel/guava-problem$ mvn -V clean test-compile
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.7.0
Java home: /usr/lib/jvm/jdk1.7.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - guava-problem:guava-problem:jar:1.0
[INFO] task-segment: [clean, test-compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: /home/mark/devel/guava-problem/target (included: [**], excluded: [])
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/guava-problem/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/guava-problem/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to /home/mark/devel/guava-problem/target/test-classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):[19,0] error: cannot find symbol
could not parse error message: symbol: static setCountImpl
location: class
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):100: error: cannot find symbol
return setCountImpl(this, element, count);
^
could not parse error message: symbol: method setCountImpl(AbstractMultiset<E>,E,int)
location: class AbstractMultiset<E>
where E is a type-variable:
E extends Object declared in class AbstractMultiset
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):105: error: cannot find symbol
return setCountImpl(this, element, oldCount, newCount);
^
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Feb 21 12:49:42 EST 2012
[INFO] Final Memory: 18M/212M
[INFO] ------------------------------------------------------------------------
Edit (again)
Having found that the source of the problem has nothing to do with Guava but rather the Maven version (see my answer), I've updated the title and question to try to be a lot more helpful to future users.
tl;dr
Maven 2 and JDK 7 are incompatible, as Maven tries to parse javac output which has changed in JDK 7.
Full explanation
Raghuram's note that this worked for him in Maven 3+ took me down the road of exploring this not as a config problem but as an actual Maven problem. I started doing more testing and found that this problem:
Occurs with Java 7 and Maven 2.2.1
Does not occur with Java 7 and Maven 3+
Does not occur with Java 6 and Maven 2.2.1
So at that point it became clear to me that the "could not parse error message" errors were relevant, and the problem probably had less to do with the guava-gwt compilation occurring and more to do with Maven not knowing how to handle the errors properly.
To test this I created a separate Maven project that has nothing to do with Guava:
├── pom.xml
└── src
└── main
   └── java
   └── ClassWithWarnings.java
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maven-problem</groupId>
<artifactId>maven-problem</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>
ClassWithWarnings.java
public class ClassWithWarnings implements java.io.Serializable {}
Lo and behold, Maven tanks on this project as well when using Java 7:
mark#mark-peters:~/devel/maven-problem$ mvn -V compile
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.7.0
Java home: /usr/lib/jvm/jdk1.7.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - maven-problem:maven-problem:jar:1.0
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/maven-problem/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/mark/devel/maven-problem/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
could not parse error message: warning: [options] bootstrap class path not set in conjunction with -source 1.3
/home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:1: warning: [serial] serializable class ClassWithWarnings has no definition of serialVersionUID
public class ClassWithWarnings implements java.io.Serializable {}
^
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Feb 21 13:10:47 EST 2012
[INFO] Final Memory: 14M/150M
[INFO] ------------------------------------------------------------------------
With Java 6, it still reports the warnings, but can parse the Javac output and so doesn't tank:
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - maven-problem:maven-problem:jar:1.0
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/maven-problem/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/mark/devel/maven-problem/target/classes
[WARNING] /home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:[1,7] [serial] serializable class ClassWithWarnings has no definition of serialVersionUID
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Feb 21 13:18:39 EST 2012
[INFO] Final Memory: 9M/150M
[INFO] ------------------------------------------------------------------------
So it seems as if the problem was that the latest Maven 2 release doesn't know how to parse error messages from Java 7+ javac. Maven 3 does. I still haven't found documentation of this and am a little surprised that Maven doesn't give a warning when it tries to compile against a JDK version that it doesn't know how to support properly.
Converting my comment to an answer...
The exact pom file along with the test class above compiles fine on my Windows box with maven 3.0.4.
The problem could be with the maven version that you are using. Or there could be other maven goals in the actual pom, which may be causing an issue.
For a similar problem I upgraded maven-compiler-plugin to a later version.
Happened to us, that we received the exact same failure, but with gradle instead of maven. After switching from ArrayListMultimap to LinkedListMultimap to error is gone. So it seems, that in version 11.0.2 at least the ArrayListMultimap is broken.
It appears that it's not trying to compile the Guava libraries, but without the full maven build log we can't tell.
Judging by the information you've posted so far, it would appear instead that you have two incompatible versions of a class or library on your classpath during compilation.
I'm going to try your test project and see if I can give you more information.
EDIT:
So I've found a couple of interesting things. First, I was able to get your project to work without a whole lot of fanfare :(
I changed your pom to:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-gwt</artifactId>
<version>11.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
By default though, your test file will not run. I refactored it so it was is now named SomeTestFileTest which will actually run the test.
I'm running Maven v2.2.1 on OSX. I also cleaned out my ~/.m2/repository before starting. I suggest you try the same: nuke your local repository folder and retry your build. If that doesn't work, let me know what version of maven you're running.

Categories