I'm currently trying to build my project with maven and sqlite4java. Which is available in the offical maven repositories.
The offical sqlite4java page on google code does have an example configuration but it's a bit outdated and does not suit my needs. I want to have a single .jar-File in the end which i can deploy elsewhere. The problem here is the shared object depedency. I am using the official build goal from their page to copy the so to the build.dir/lib but my assembly goal crashes with:
[INFO] Failed to create assembly: Error adding file-set for 'com.almworks.sqlite4java:libsqlite4java-linux-i386:so:0.282' to archive: Error adding archived file-set. PlexusIoResourceCollection not found for: /home/lhw/.m2/repository/com/almworks/sqlite4java/libsqlite4java-linux-i386/0.282/libsqlite4java-linux-i386-0.282.so
No such archiver: 'so'.
What am I doing wrong? Here is my current pom.xml stripped from some dependencies unrelated to this topic
<?xml version="1.0"?>
<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>de.ring0.lhw</groupId>
<artifactId>system</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.almworks.sqlite4java</groupId>
<artifactId>sqlite4java</artifactId>
<version>${sqlite4java.version}</version>
</dependency>
<dependency>
<groupId>com.almworks.sqlite4java</groupId>
<artifactId>libsqlite4java-linux-i386</artifactId>
<version>${sqlite4java.version}</version>
<type>so</type>
</dependency>
</dependencies>
<properties>
<sqlite4java.version>0.282</sqlite4java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.almworks.sqlite4java</groupId>
<artifactId>libsqlite4java-linux-i386</artifactId>
<version>${sqlite4java.version}</version>
<type>so</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<skipTests>true</skipTests>
<systemProperties>
<property>
<name>sqlite4java.library.path</name>
<value>${project.build.directory}/lib</value>
</property>
</systemProperties>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>de.ring0.lhw.Init</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Edit :
I think that the jar-with-dependencies assembly descriptor tries to unpack the dependencies.
See the link :
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
maven.apache.org/plugins/maven-assembly-plugin/… ...
<unpack>true</unpack>
And of course it fails to unpack the .so
So you might have to use a custom assembly to perform what you want to do
It is possible to create executable jar with stock "jar-with-dependencies" assembly descriptor and without using any startup shell/batch scripts. However, it requires dirty workarounds that doesn't involve much Maven configurations.
We need to place all native libraries (included in sqlite4java zip download) to src/main/resources directory. Also remove sqlite4java native library dependency from your Maven POM file.
Because sqlite4java's native library loader doesn't look at your classpath or inside of JAR file, you have to extract native libraries at startup, and set "sqlite4java.library.path" system property at runtime. Please see the following sample code:
/** List of native libraries you put in src/main/resources */
public static final String[] NATIVE_LIB_FILENAMES = {
"libsqlite4java-linux-amd64.so",
"libsqlite4java-linux-i386.so",
"libsqlite4java-osx.jnilib",
"libsqlite4java-osx-10.4.jnilib",
"libsqlite4java-osx-ppc.jnilib",
"sqlite4java-win32-x64.dll",
"sqlite4java-win32-x86.dll",
};
/**
* Extract native libraries to the current directory.
* This example needs Apache Commons IO (https://commons.apache.org/proper/commons-io/)
*/
public static void extractNativeResources() {
for(String filename: NATIVE_LIB_FILENAMES) {
// Change "DemoSQLite2" to your class name
final InputStream in = DemoSQLite2.class.getResourceAsStream("/"+filename);
if(in != null) {
try {
System.out.println("Extracting " + filename);
FileUtils.copyInputStreamToFile(in, new File(filename));
} catch (IOException e) {
System.err.println("Can't extract " + filename);
e.printStackTrace();
}
}
}
}
/**
* Delete native libraries in the current directory
*/
public static void removeNativeResources() {
for(String filename: NATIVE_LIB_FILENAMES) {
File file = new File(filename);
file.delete();
}
}
public static void main(String[] args) throws Exception {
boolean deleteNativesOnExit = false; // Delete natives on exit
// Extract native libraries if sqlite4java.library.path property is not set
String sqlitePath = System.getProperty("sqlite4java.library.path");
if(sqlitePath == null) {
System.setProperty("sqlite4java.library.path", "."); // Read natives from current directory
extractNativeResources();
deleteNativesOnExit = true;
}
// Do SQLite jobs here
final SQLiteConnection db = new SQLiteConnection(new File("test.db"));
try {
db.open();
db.dispose();
System.out.println("Success");
} catch (Exception e) {
e.printStackTrace();
System.err.println("FAILED");
}
// Delete the native libraries we extracted
if(deleteNativesOnExit) removeNativeResources();
}
Now your app should be buildable with standard "jar-with-dependencies" descriptor, and your app is runnable with standard "java -jar your_jar.jar" command.
Of course, if sqlite4java gets updates in future, you have to manually update the native libraries in your resource directory.
If you have a better, less dirty solution, please let me know!
Related
I'm using Quarkus 2.0 to build uber-jar to be used as AWS lambda.
Maven build script is as follows:
<properties>
<quarkus.package.type>uber-jar</quarkus.package.type>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-amazon-lambda</artifactId>
</dependency>
</dependencies>
<build>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>2.0.3.Final</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
application.properties also contains the quarkus.package.type=uber-jar config.
When I debug Maven build, I see that in the moment of making decision, quarkus-maven-plugin executes the code:
#BuildStep
public JarBuildItem buildRunnerJar(CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem outputTargetBuildItem, TransformedClassesBuildItem transformedClasses, ApplicationArchivesBuildItem applicationArchivesBuildItem, ApplicationInfoBuildItem applicationInfo, PackageConfig packageConfig, ClassLoadingConfig classLoadingConfig, List<GeneratedClassBuildItem> generatedClasses, List<GeneratedResourceBuildItem> generatedResources, List<UberJarRequiredBuildItem> uberJarRequired, List<UberJarMergedResourceBuildItem> uberJarMergedResourceBuildItems, List<UberJarIgnoredResourceBuildItem> uberJarIgnoredResourceBuildItems, List<LegacyJarRequiredBuildItem> legacyJarRequired, QuarkusBuildCloseablesBuildItem closeablesBuildItem, List<AdditionalApplicationArchiveBuildItem> additionalApplicationArchiveBuildItems, MainClassBuildItem mainClassBuildItem, Optional<AppCDSRequestedBuildItem> appCDS) throws Exception {
if (appCDS.isPresent()) {
this.handleAppCDSSupportFileGeneration(transformedClasses, generatedClasses, (AppCDSRequestedBuildItem)appCDS.get());
}
if (!uberJarRequired.isEmpty() && !legacyJarRequired.isEmpty()) {
throw new RuntimeException("Extensions with conflicting package types. One extension requires uber-jar another requires legacy format");
} else if (legacyJarRequired.isEmpty() && (!uberJarRequired.isEmpty() || packageConfig.type.equalsIgnoreCase("uber-jar"))) {
/* I want it get there, but it doesn't due to "legacyJarRequired" containing an item, ("packageConfig == uber-jar" as expected) */
return this.buildUberJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem, packageConfig, applicationInfo, generatedClasses, generatedResources, uberJarMergedResourceBuildItems, uberJarIgnoredResourceBuildItems, mainClassBuildItem);
} else {
/* execution gets there because "legacyJarRequired" contains an item */
return legacyJarRequired.isEmpty() && !packageConfig.isLegacyJar() && !packageConfig.type.equalsIgnoreCase("legacy") ? this.buildThinJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem, packageConfig, classLoadingConfig, applicationInfo, generatedClasses, generatedResources, additionalApplicationArchiveBuildItems, mainClassBuildItem) : this.buildLegacyThinJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem, packageConfig, applicationInfo, generatedClasses, generatedResources, mainClassBuildItem);
}
}
And item in the legacyJarRequired is added in here
#BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class)
public void requireLegacy(BuildProducer<LegacyJarRequiredBuildItem> required) {
required.produce(new LegacyJarRequiredBuildItem());
}
How can I avoid adding this element into build config to receive versioned xxx-yyy-zzz-runner.jar from my application build?
function.zip is built all right, but it's not an option for me, because I'd like to push the results of the build to maven repo.
I also needed to deploy an uber-jar to artifactory, for further deployment as AWS lambda. Finally I solved it with build-helper-maven-plugin:attach-artifact plugin. It attached function.zip to artifact in Nexus, so Jenkins was able to get the archive and deploy it to AWS.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>./target/function.zip</file>
<type>zip</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
package Bots;
public class FirstBot {
public static void main(String[] args) {
// Insert your bot's token here
String token = "TheToken";
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
String prefix = "!";
// Add a listener which answers with "Pong!" if someone writes "!ping"
api.addMessageCreateListener(event -> {
if (event.getMessageContent().equalsIgnoreCase(""+prefix+"ping")) {
event.getChannel().sendMessage("Pong!");
}
});
// Print the invite url of your bot
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
}
}
I am new to creating Discord bots in Java. I am using Eclipse and i used this starter code ^
It is giving me an error that DiscordApi cannot be resolved to a type and DiscordApiBuilder cannot be resolved to a type
The first thing you need to do is make sure that you have the JavaCord Maven dependency set up correctly.
Add this inside the <dependencies> field of your pom.xml:
<dependency>
<groupId>org.javacord</groupId>
<artifactId>javacord</artifactId>
<version>3.3.0</version>
<type>pom</type>
</dependency>
The next step is to shade the JavaCord package into your final jar, so that you can run it directly. Add this to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<relocations>
<relocation>
<pattern>org.javacord</pattern>
<shadedPattern>your.package.name.here.dependencies.javacord</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you already have a <build> or <plugins> field, put it within that.
The final step is to import the relevant JavaCord classes into your main class. If you try to type out the class names again, Eclipse should offer the option to import them.
I want to build a Java project using Maven with parameters, which change in every build. One parameter is for example a key which is checked inside of the program.
The parameters should not be able to be read out once the project is build. Tried different Approche including plugins from org.codehaus.mojo… but having problems "plugin execution not covered by lifecycle"....
/****************************/
/**read property values */
/****************************/
//Create a new property list
Properties properties = new Properties();
//create a input strem
InputStream inputStream = null;
//try to read the property file
try {
String filename ="restApi.properties";
inputStream = Main.class.getClassLoader().getResourceAsStream(filename);
if(inputStream==null) {
System.out.println("Unable to read required properties");
}
properties.load(inputStream);
System.out.println(properties.getProperty("property_mainUrlValue"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
my pom.xml
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<property_mainUrlValue>property_mainUrlValue</property_mainUrlValue>
<properties>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/restApi.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
error shown in eclipse
Unable to read required properties
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at itAsset.Main.main(Main.java:58)
I guess that you are searching for what Maven calls (for some reason which I do not understand) "filtering".
The basic idea is this:
You turn on the feature by including the following configuration into pom.xml:
...
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
This causes that when you run mvn resources:resources -Dkey="mmm123", and you have a resource src/main/resources/restApi.properties containing line
appKey=${key}
then Maven will create a resource output in target/classes/restApi.properties which contains
appKey=mmm123
The detailed description is here: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
I'm Trying to execute an *.exe file after extracting it from the project resources to a local/temporary path. It is working fine when I run the code through NetBeans. The problem comes when I build it for an Standalone Jar. Simply doesn't run, is not extracting the resource and not executing it.
I omitted the instantiation for brevity.
public class MyClass {
public MyClass() {
}
public void extractExe() {
try {
// Get resource as stream
InputStream in = getClass().getResourceAsStream("/resource.exe");
// Set the output path for the stream
OutputStream out = new FileOutputStream("C:/path/to/resource.exe");
// Copy the resource to the path
IOUtils.copy(in, out);
// Close the streams
in.close();
out.close();
// Execute it !
Runtime.getRuntime().exec("cmd /c start C:/path/to/resource.exe");
} catch (FileNotFoundException ex) {
System.out.println(ex);
} catch (IOException ex) {
System.out.println(ex);
}
}
}
And this is how my pom.xml looks like, it just load the dependencies, and builds a jar with the libraries included within it:
<?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>com.jeflopo</groupId>
<artifactId>Myclass</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${project.artifactId}-standalone</finalName>
<archive>
<manifest>
<mainClass>com.jeflopo.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
It works fine and no errors given When I execute it in Netbeans or through the commandline with:
java -cp myjar.jar com.jeflopo.Main
But It doesn't work when I doubleclick the .jar
I'm not an expert, could anyone help me to debug the error ?
I don't really know what I have done to make it work again. But It's working now.
I have executed it by command line, I have run the command "mvn package" and still It wasn't working launching by double click.
I just went to eat, and when I have returned I have tried again... And now it launch.
Ehm... #Sajan Chandran suggested to show the manifest file, but I think that since i'm not using maven-jar-plugin I haven't a manifest file. I'm just using maven-assembly-plugin to assemble all the dependencies in just one distributable archive.
Thanks anyway.
And excuse my grammar, english isn't my first lang...
I've created a test which extends GWTTestCase but I'm getting this error:
mvn integration-test gwt:test
...
Running com.myproject.test.ui.GwtTestMyFirstTestCase
Translatable source found in...
[WARN] No source path entries; expect subsequent failures
[ERROR] Unable to find type 'java.lang.Object'
[ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core' either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.1 sec <<< FAILURE!
GwtTestMyFirstTestCase.java is in /src/test/java, while the GWT module is located in src/main/java. I assume this shouldn't be a problem.
I've done everything required according to http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html and of course that my gwt module already has com.google.gwt.core.Core indirectly imported.
<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.myproject</groupId>
<artifactId>main</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Main Module</name>
<properties>
<gwt.module>com.myproject.MainModule</gwt.module>
</properties>
<parent>
<groupId>com.myproject</groupId>
<artifactId>app</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>app-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputFile>../app/src/main/webapp/WEB-INF/main.tree</outputFile>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>
${project.build.directory}/${project.build.finalName}/${gwt.module}
</classesDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is the test case, located in /src/test/java/com/myproject/test/ui
public class GwtTestMyFirstTestCase extends GWTTestCase {
#Override
public String getModuleName() {
return "com.myproject.MainModule";
}
public void testSomething() {
}
}
Here is the gwt module I'm trying to test, located in src/main/java/com/myproject/MainModule.gwt.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name='com.myproject.Commons' />
<source path="site" />
<source path="com.myproject.test.ui" />
<set-property name="gwt.suppressNonStaticFinalFieldWarnings" value="true" />
<entry-point class='com.myproject.site.SiteModuleEntry' />
</module>
Can anyone give me a hint or two about what I'm doing wrong?
To reproduce the solution used by KevinWong from the maven-gwt-plugin doc, which worked for me after losing over an hour trying the other solutions.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
<systemProperties>
<property>
<name>gwt.args</name>
<value>-out \${webAppDirectory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
I don't think the right thing to do is just to exclude the tests from your maven life cycle. What's the point of writen them? What you have to do is to properly configure the maven-surefire-plugin in order to make it work.
You see, that plugin uses a system classloader to look up the classes but GWTTestCase needs an URLClassLoader. That's the reason you are getting [WARN] No source path entries; expect subsequent failures. and the following ClassNotFoundException. No worries, though. It's easy to tell maven to use a URLClassLoader instead:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/java</additionalClasspathElement>
<additionalClasspathElement>${basedir}/src/test/java</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
Please, notice the <userSystemClassLoader>false</useSystemClassLoader> entry.
Also, notice that I added the sources of my tests and main directories in order to allow GWT find the needed classes to generate the Javascript. You might need to configure it differently.
The problem was that the test was run by surefire instead of gwt-maven plugin. I had to explicitly exclude my gwt tests from surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*GwtTest*.java</exclude>
<exclude>**/*Gwt*Suite*.java</exclude>
</excludes>
</configuration>
</plugin>
I still can't run my GWTTestCase tests, but that's another problem and subject for another question. I consider this issue solved.
First exclude gwt testcases from maven-surefire-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<excludes>
<exclude>**/*GwtTest.java</exclude>
</excludes>
</configuration>
</plugin>
Then configure gwt-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>**/*GwtTest.java</includes>
<mode>htmlunit</mode>
</configuration>
</plugin>
Now you can easily run gwt testcases using gwt:test.
I am very confident that this error has nothing to do with maven setup. My first guess would be that tests are not on gwt compile path... I guess the problematic source code is:
<source path="com.myproject.test.ui" />
try changing to:
<source path="com/myproject/test/ui" />
or whatever is the appropriate path.
the solution to this
"[ERROR] Unable to find type 'java.lang.Object'
[ant:java] [ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core'
either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')"
GWT compilation error is to use "fork='true'" when invoking GWT compiler.
that's why the solutions posted here magically worked - they have "forkMode=always" and similar.
here's how I call GWT compiler:
ant.java(classname: 'com.google.gwt.dev.Compiler', failOnError: 'yes', maxmemory: '1000m', fork: 'true')
and here's the full GWT compiler call in Gradle:
war {
// Exclude unneccessery GWT Compiler artifacts
exclude "**/gwt-unitCache/**"
}
task widgetset << {
// Create widgetset directory (if needed)
def created = (new File(gwtBuildDir)).mkdirs()
// Compile
ant.java(classname: 'com.google.gwt.dev.Compiler', failOnError: 'yes', maxmemory: '1000m', fork: 'true')
{
classpath {
pathElement(path: configurations.compile.asPath)
pathElement(path: sourceSets.main.runtimeClasspath.asPath)
sourceSets.main.java.srcDirs.each {
pathelement(location: it.absolutePath)
}
}
arg(line: '-war ' + gwtBuildDir)
arg(line: '-logLevel INFO')
arg(line: '-style OBF')
arg(line: '-localWorkers 2')
arg(line: widgetsetClass)
// jvmarg(value: '-Djava.awt.headless=true')
// jvmarg(value: '-XX:MaxPermSize=256M')
// jvmarg(value: '-Xmx500M')
}
}
// Require widgetset compilation before WAR is built
war.dependsOn widgetset
This sunfire config worked for me.