0

I read this SO post and followed the steps but still I am unable to run it.

I tried running it as follows

Directory_where_jar_is_located $ java -jar Main.java
Error: Unable to access jarfile IcerbergRun
Directory_where_jar_is_located$ java -jar ProjectName.jar 
Error: Could not find or load main class IcebergRun

What needs to be done after this? What are those dependencies? Also, I am sharing my pom.xml that has some bunch of libraries that are required for my project.

enter image description here

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>SparkIceberg</groupId>
<artifactId>SparkTut</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <!--<logger name="org.apache.catalina.core" level="OFF" />-->
            </configuration>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>


<dependencies>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.11</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_2.11</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.11.417</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-spark</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-data</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-common</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-api</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-core</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-parquet</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.Netflix.iceberg</groupId>
        <artifactId>iceberg-orc</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-aws</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-hdfs</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.parquet</groupId>
        <artifactId>parquet-common</artifactId>
        <version>1.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.parquet</groupId>
        <artifactId>parquet-column</artifactId>
        <version>1.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.parquet</groupId>
        <artifactId>parquet-hadoop</artifactId>
        <version>1.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.avro</groupId>
        <artifactId>avro</artifactId>
        <version>1.8.2</version>
    </dependency>
</dependencies>

Atihska
  • 4,803
  • 10
  • 56
  • 98
  • See https://stackoverflow.com/a/42200519/104891. If it doesn't help, please share the [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – CrazyCoder Oct 01 '18 at 19:31
  • It's usually `Directory_where_jar_is_located $ java -jar jar_file_name.jar` – lealceldeiro Oct 01 '18 at 19:56
  • @CrazyCoder I tried the above question but I did not understand some stuff. As requested, I added some more info by editing my question. Please let me know further. – Atihska Oct 01 '18 at 21:12
  • @Atihska it looks like you have this problem: https://stackoverflow.com/a/45169655/104891, https://stackoverflow.com/a/50303815/104891. – CrazyCoder Oct 01 '18 at 21:14
  • @CrazyCoder: How do you see what's inside JAR? I tried default Jar utility that gets in Mac with Java installation that didn't work. Also, I am not sure if my dependencies are being build inside JAR. How do you make sure about some external dependencies. – Atihska Oct 01 '18 at 21:23
  • @Atihska jar is basically a ZIP, so you can use any archive manager to browse inside, or just unpack it to see. – CrazyCoder Oct 01 '18 at 21:24
  • @CrazyCoder Tried that too but on uncompressing I am getting `SparkTut.zip.cpgz` created. Tried on terminal using unzip and its unzipping. – Atihska Oct 01 '18 at 21:27
  • @Atihska https://askubuntu.com/questions/239407/using-terminal-to-open-a-file-within-a-jar-file – CrazyCoder Oct 01 '18 at 22:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181113/discussion-between-atihska-and-crazycoder). – Atihska Oct 01 '18 at 22:29

2 Answers2

0

I created a Test project in java and built and executed the jar.

Initially the structure of project looked as shown below. The out directory contains only production directory. Initial

Now click on File-> Project Structure->Artifacts. Click on + sign next to left navigation pane in the upper left corner.

enter image description here

Now click on + sign and select Jar->from module with dependencies.... A dialog box will appear as shown below:

enter image description here

Now select the Main Class and select the radio button in front of extract to the target JAR and click OK. You will see the following enter image description here:

Check the Include in project build checkbox and click Apply->Ok.

enter image description here

Click on Build->Build Project. Now you can see that out directory has artifacts sub-directory which will have corresponding jar

enter image description here

Now on the terminal in intelliJ go inside directory where jar is present and execute the command java -jar JAR_NAME.jar and you can see that main function is executed.

Yug Singh
  • 3,112
  • 5
  • 27
  • 52
  • Still unable to run it. I get `Error: Could not find or load main class IcebergRun` – Atihska Oct 01 '18 at 20:54
  • Did you mention your main class in dialog box appear after clicking on `+` sign? Also please check do you have a class with `main function`? – Yug Singh Oct 01 '18 at 21:00
  • @Atihska I build a jar without having main function inside any class. When i execute the jar I get the error `Error: Could not find or load main class `. – Yug Singh Oct 01 '18 at 21:07
  • Yes I have a class with. main function and I specified my main after clicking `+`. Please check my edits. – Atihska Oct 01 '18 at 21:09
  • @Atihska look into solutions shared in https://stackoverflow.com/q/10654120/6407858 – Yug Singh Oct 01 '18 at 21:24
  • Not able to make it work still. I checked that my Main class exists. Using `$ jar tf IcebergJava.jar | grep Main`, I get `com/example/Main.class`. But still getting could not find or load main class com.example.Main. This means its reading the manifest file. – Atihska Oct 02 '18 at 18:37
0

So I am not sure why my IntelliJ produced JAR was unable to execute and getting Could not load main class so I tried my entire java project on command line and generated the JAR that worked for me.

Here are the steps:

1. Install maven on ec2 https://gist.github.com/sebsto/19b99f1fa1f32cae5d00

$sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
$sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
$sudo yum install -y apache-maven
$mvn —version

2. Install the following as well

$sudo yum install java-1.8.0-openjdk-devel
$yum install zip

3. Do this to create maven project http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/

$mvn archetype:generate -DgroupId=com.package.name -DartifactId=java-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

4. Edit code files and pom.xml. You can open the project in IntelliJ and edit.

5. MAVEN BUILD: Run from root dir of your java project

java-project$mvn package or mvn clean package

6. Remove these files created after build

https://gist.github.com/hkhamm/88923412992d284580ea

java-project$zip -d target/iceberg-project-1.0-SNAPSHOT.jar META-INF/*.RSA META-INF/*.DSA META-INF/*.SF

7. Run JAR

java-project$java -cp target/java-project-1.0-SNAPSHOT.jar com.project.name.App
Atihska
  • 4,803
  • 10
  • 56
  • 98