intellij scala create executable jar file - scala

H everybody! I'm trying to create an executable jar file from a scala project in Intellij. At the moment my artifact looks like this:
and the artifact builds fine. When I try to run the artifact on the command line however I get:
[edouard#localhost datagenerator_jar]$ java jar datagenerator.jar
Erreur : impossible de trouver ou charger la classe principale jar
(Error : cannot find or load main class jar)
Does anybody know what I'm doing wrong? As far as I know, the Main Class is defined correctly (It is the one suggested for my project by the Intellij plugin)

You actually issued a wrong launch command.
You should do
java -jar datagenerator.jar
Without "jar" being an option (with "-"), a main class named "jar" were searched (and not found).

Related

How to run scala spark intellij-idea project in mac terminal?

I um using intellj IDE for my spark project using scala. The requirement is to run the program from the terminal by passing the csv filename to the project using terminal.
My project structure is as follows:
Scaladatavalidaton:
-src
-main
-scala
-ValidationPackage
-validator.scala
-test
so what I am looking for is :
command_name Scalafilename_to_be_run CSVfilename_to_be_Validated
I tried using sbt run but I got main class not detected error even though I have specified the main object.

IntelliJ build wrong JAR: Could not find or load main class

I have a simple example
public class FileSystemReadFile {
public static void main(String[] args) throws IOException {
System.out.println("Reading the file" + args[0]);
}
}
which is created in IntelliJ where I want to build JAR file; So what I did:
Added Artifact with dependencies (presumably I have some);
Ensure that MANIFEST.MF is located in src\main\resources\META-INF\ as it is already mentioned somewhere here on the site.
Run Artifact build which gave me JAR file in out folder and I run that jar file that said me "Could not find or load main class" java <name>.jar
You may see that main class is added into MANIFEST and location of manifest is also fine.
When I open that created JAR file, I see the same MANIFEST content, I see lots of dependency modules, but I don't see my class!
I suspect that is a cause. Any ideas?
If you include any signed JARs in your app and then use IntelliJ to build artifacts, it will extract the JARS and bundle them with your compiled output.
This then causes a JAVA security exception. I've seen this with Eclipse Paho and Bouncy Castle which are signed.
You can check if any of the library JARs you are using are signed using the jarsigner tool.
jarsigner -verify -verbose <path to library JAR>
Change your IntelliJ artifact setup so that these get bundled as libraries instead of being extracted. Extraction invalidates the certificate as you'd expect.
Try creating a dummy project with just Main. Add 1 library JAR (that you are trying to build with) at a time. Build an output JAR each time until Main breaks. That's how I found this.
IntelliJ should warn you.....
Not sure what was with IntellJ, but I rebuilded artifacts again and it was ok.
hadoop jar <Jar-name>
java -jar <Jar-name>
Everything is working fine.

Build error deploying javafx application when added jna 4.1.0 library

I am trying to build my app, but I have the next error.
The jar libs\jna-4.1.0.jar has a main class com.sun.jna.Native that does not match the declared main com.bp.ocr.MainApp
I do not know how to solve it, I am looking for but I am not understand why happens.
Using base JDK at: C:\Program Files\Java\jdk1.8.0_31\jre
The jar libs\jna-4.1.0.jar has a main class com.sun.jna.Native that
does not match the declared main com.bp.ocr.MainApp
Bundler EXE Installer skipped because of a configuration problem:
Main application jar is missing.
Advice to fix: Make sure to use fx:jar task to create main application jar.
BUILD SUCCESSFUL

Error while trying to run the jar file in command prompt

My requirement is to run a eclipse java project in command prompt. I am using following program structure:
project name:parser
package name:xml
class name:Sample (with the main method)
I tried exporting the jar file by right clicking the project name-->export-->jar file-->gave the destination path for jar file->checked the Generate Manifest file and selected the main program(Sample.java).
Now in the command prompt i tried to run the jar file in the cmd using
java -jar myjar.jar.
And the error message I get is:
Exception in thread "main" java.lang.UnsupportedClassVersionError: XML/Sample:
Unsupported major.minor version 51.0
Could not find the main class: XML.Sample. Program will exit.
I have been searching for a solution for a long time but failed to find one. I would be very thankful if someone could help me with this problem. Kindly excuse for any mistakes in my question as I am new to java coding. Thanks in advance

Scala SBT: standalone jar

The answer: Making stand-alone jar with Simple Build Tool seems like what I need, but it did not have enough information for me, so this is a followup.
(1) How do I adapt the answer to my need? I don't understand what would need to be changed.
(2) What command do I run to create the standalone jar?
(3) Where can I find the jar after it has been created?
What I've tried:
Pasting the code in the linked answer verbatim into my: project/build/dsg.scala file. The file now has a
class ForkRun(info: ProjectInfo) extends DefaultProject(info)
(from before, used for running projects in a separate VM from SBT) and the new:
trait AssemblyProject extends BasicScalaProject
from the linked answer.
I also tried pasting the body (all defs and the lazy val of the AssemblyProject into the body of ForkRun.
To create a jar I ran package at the SBT prompt and get:
[info] Packaging ./target/scala_2.8.1/dsg_2.8.1-1.0.jar ...
[info] Packaging complete.
So I tried running the dsg_2.8.1-1.0.jar from the shell via:
java -jar dsg_2.8.1-1.0.jar
But I get:
Failed to load Main-Class manifest attribute from
dsg_2.8.1-1.0.jar
Could this be caused by having multiple entry points into my project? I select from a list when I execute run from the SBT prompt. Perhaps I need to specify the default when creating the package?
Here's a writeup I did on one way to make an executable jar with SBT:
http://janxspirit.blogspot.com/2011/01/create-executable-scala-jar-with-sbt.html
sbt-assembly is a sbt plugin to create a standalone jar of Scala sbt project with all of its dependencies.
Refer this post for more details with an example.