I have used GRAALVM to compile native JavaFX apps. in commands ports. Here I want to do the same thing using maven.
I have GRAALVM latest version install in C and added the Environment variable as the name GRAALVM_HOME. and in PATH %GRAALVM_HOME%\bin but when I Run client:build-in IntelliJ. it says GRAAL_PATH didn't find.
I tried to do it with the client plugin.
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<version>${client.plugin.version}</version>
<configuration>
<target>${client.target}</target>
<mainClass>${main.class}</mainClass>
<bundlesList>
<list>com.example.sample.main</list>
</bundlesList>
<reflectionList>
<list>com.example.sample.MainController</list>
</reflectionList>
<graalvmHome>GRAALVM_HOME</graalvmHome>
</configuration>
</plugin>
inline graalvmhome I set to add the entire path that's didn't work. then I added a GRAALVM_HOME in it. but this didn't work either.
it's <graalvmHome>path to graal</graalvmHome> where path to graal is the path in your local machine e.g. /home/user/graal
Related
I have different Java test behaviours (probably after a MacOS update to Big Sur 11.2.3 or another system).
My JUnit test requires the variable DYLD_LIBRARY_PATH on Mac and LD_LIBRARY_PATH on Ubuntu (mvn surefire is used, see below) to find some dylibs / shared objects.
Test works in IntelliJ without any problems on both OS.
But during the mvn build the DYLD_LIBRARY_PATH variable (System.getenv(..)) is null and the test fails on Mac (on Ubuntu it works). Starting mvn with '-X' shows that surefire sets the DYLD_LIBRARY_PATH, but later it is still null.
I am using maven-3.6.3, surefire 3.0.0-M5 and OpenJDK 11.0.10.
Any ideas, how I can with the environment issue?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<LD_LIBRARY_PATH>${basedir}/src/main/resources/libs</LD_LIBRARY_PATH>
<DYLD_LIBRARY_PATH>${basedir}/src/main/resources/libs</DYLD_LIBRARY_PATH>
</environmentVariables>
</configuration>
</plugin>
Pls report a bug in our JIRA and attach your project in ZIP. We need to reproduce it and debug the plugin but the project is required.
ive imported a bunch on maven projects from svn and they all (...a lot) try to use
JRE System Library [JavaSE-1.7]
But i only have
jdk1.8.0_102_64Bit
Which i told eclipse about in eclipse.ini with:
-vm C:\Users\myuser\Downloads\jdk1.8.0_102_64Bit\bin
Yet all the imported maven projects insist to use the "System JRE" which is unbound when i check it.
How do you tell maven to use what eclipse knows about? or where does maven get its information about JDK's / JRE'S?
Maven by default uses JAVA_HOME Environment Variable to know which java version to use. Unless you set different one in pom.xml.
Try check every pom.xml of your projects, they must have a plugin section like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_6_HOME}/bin/javac</executable>
</configuration>
</plugin>
Executable tag tell maven to use java 6 in this example.
In this case i probably did something wrong while importing it from svn..a second try worked, but im not sure why :(
I have a Maven project that I need somehow to compile so I'd be able to transfer the compiled file to a different machine and then execute there (with potentially different Java version).
I looked at this SO question
and was able to execute:
mvn clean install
mvn dependency:copy-dependencies
Yet when I tried:
cd target/
java -cp myApp-0.0.1.jar:dependency myApp
I got
Error: Could not find or load main class myApp
My pom.xml does not have mvn-assembly-plugin or maven-jar-plugin (and I successfully get the .jar in target/ after mvn clean install).
I am not sure whether those steps are related to my goal because what I need is to create something that will run without any java -jar or mvn and could be ported and run on a different machine.
There is Maven build plugin that would bundle all your dependencies in a JAR. You could execute it simply with
java -jar mybundled.jar
without caring about class path dependencies.
And here comes the Maven plugin. Replace the MainClass with your entry point.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.yourdomain.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
As it is bound to the package lifecycle, you would find your bundled JAR in your target directory after doing a ...
mvn package
Regarding your concern that your code won't run on another machine, Java is platform-independent and generally you can rely on that. However, three things come to my mind that can make life hard:
Your code depends on the system encoding. Maven should give you a warning on that in the log, advising you to specify it explicitly.
You interact with the runtime, like executing system commands. ps won't work on windows and dir /s probably not on *nix.
The version of your Java environment differ. Of course, JavaFX code won't run with a Java 1.5. If you use the latest features, make sure your clients already have the respective version or, at least, are able to get it from somewhere. You might want to take a look at the source and target compile options, too: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#crosscomp-example
I am trying to create a maven web app, which will be part of my maven ear application. I tried creating web app from command line as well as from option within eclipse but both ways giving me error like "Dynamic Web Module 3.1 requires Java 1.7 or newer." I tried changing build path JDK to Java 1.8 and compiler level to 1.8 and saved but this didn't resolve the issue. When I do right click on project "maven update", the JDK again getting reset to old one not sure why it's not saving my changes. Is it issue with eclipse(I tried both LUNA and MARS version of eclipse)? How to resolve this issue as it's not letting me run my application from eclipse.
Also I am getting this access restriction warning "Access restriction: The type 'XmlElement' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar')". If I remove JDK from build path and add it again it disappears. But when maven update is done error reappears. Please someone suggest me how to resolve these issues ?
Add following in pom.xml and do maven update
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
I am brand new to both java and to maven, so this is likely very simple.
If I follow the maven2 hello world instructions here:
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
everything works OK. If I then alter pom.xml to bring in a dependency from a remote repository, the files for this dependency get stored in ~/.m2/repository/new-dependency/.
Using the syntax in the hello world instructions to run the application requires that I add the absolute path to the dependency to my classpath (either by setting the environment variable or via the command line switch):
java -cp target/my-app-1.0-SNAPSHOT.jar:/.../.m2/.../new-dependency.jar com.mycompany.app.App
This will obviously get unwieldy quickly :)
I suspect that this is not the usual way of running a java program and that I just need to read more about .jar files, but while I am doing so I would appreciate any tips on how to do this properly.
I am not using an IDE, btw. vim from the command line.
Thanks!
Mike.
You can use maven itself to run it, I believe it sets the classpath for you.
mvn compile
will compile it
then you run:
mvn exec:java -Dexec.mainClass="com.mycompany.app.App"
which will execute it.
You can see http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ for some more info on ways to run (including passing command-line args to the thing you want to run)
You can make a jar executable by adding the Main-Class attribute to its manifest file. In Maven this is done by the archiver plugin. To add the Main-Class attribute, add this to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
You can now run your jar with the command: java -jar myjar.jar or by double clicking on it (not available in all platforms).
If you want it simple for you and others, then you can generate a jar with all dependencies in it, using the maven-assembly-plugin. Example is here: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html, section Execution: Building an Assembly
You can use the maven-shade-plugin which will create an executable uber war with all dependencies.
OR
Use the appassembler-plugin which creates a script that imports all dependencies and lets you execute a main class from the command line.