I have .Jar file with only .class files in there without any .java files...
I cloned a git repository:
https://github.com/kaist-dmlab/k-Medoid/tree/master/MR-KMEDIAN
the repository has a .jar file as well, but no .pom file with the java code. So I created a Maven Project in Eclipse, created a package: com.parallel.WEIGHTED_KMEDIAN
and put the files in there. This is what the directory looks like:
I checked all the dependencies in the java files and looked them up on the maven website and added them. So my pom.xml file looks like this:
<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.parallel</groupId>
<artifactId>WEIGHTED_KMEDIAN</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WEIGHTED_KMEDIAN</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run the .jar file on AZURE HDINSIGHTS I get an error:
When I compared the .jar file I created and the one in the project, I am missing all the .java files.
Is this the issue that azure doesn't like?
How can I add the .java files in the .jar file?
I created the jar file from eclipse going into run>maven build> clean install
files in my jar:
files in jar from git repo:
so far I have tried:
<sourceDirectory>src/main/java/com/parallel</sourceDirectory>
Updating MAVEN project
clean compile install
The solution was the project directory needed to be in a specific format, it should be under main/resources and then follow the path in the groupID specified in the POM.xml file:
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.parallel</groupId>
<artifactId>WEIGHTED_KMEDIAN</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WEIGHTED_KMEDIAN</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Dependencies:
Related
Our product has more four web modules; the maven script of the individual module builds the war file of respective web-modules by bringing all the dependencies as mentioned in pom.xml. We are also doing an overlay of a third-party module that copies additional jar files into WEB-INF/lib folder.
In the end, To simplify the distribution we are trying to create a single enterprise archive (ear) file which includes all war files along with its dependencies.
The maven-ear plugin, we are using copies only the jar files mentioned in pom.xml of sub-modules, not the ones copied by the result of the overlay.
Any help on this much appreciated.
<?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">
<parent>
<artifactId>web</artifactId>
<groupId>org.dept.prod</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>singleear</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>ear</packaging>
<properties>
<mod.version>7.12.0.Final</mod.version>
</properties>
<dependencies>
<dependency>
<groupId>org.dept.prod</groupId>
<artifactId>common</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.dept.prod</groupId>
<artifactId>module1</artifactId>
<version>2.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.dept.prod</groupId>
<artifactId>module2</artifactId>
<version>2.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.dept.prod</groupId>
<artifactId>module3</artifactId>
<version>2.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.dept.prod</groupId>
<artifactId>module4</artifactId>
<version>2.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.3rdparty.module</groupId>
<artifactId>other</artifactId>
<version>x.x.x.Final</version>
<scope>runtime</scope>
</dependency>
<!-- Dependencies used by project -->
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<skinnyWars>true</skinnyWars>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<modules>
<webModule>
<groupId>org.dept.prod</groupId>
<artifactId>module1</artifactId>
<bundleFileName>/module1.war</bundleFileName>
<contextRoot>/module1</contextRoot>
</webModule>
<webModule>
<groupId>org.dept.prod</groupId>
<artifactId>module2</artifactId>
<bundleFileName>/module2.war</bundleFileName>
<contextRoot>/module2</contextRoot>
</webModule>
<webModule>
<groupId>org.dept.prod</groupId>
<artifactId>module3</artifactId>
<bundleFileName>/module3.war</bundleFileName>
<contextRoot>/module3</contextRoot>
</webModule>
<webModule>
<groupId>org.dept.prod</groupId>
<artifactId>module4</artifactId>
<bundleFileName>/module4.war</bundleFileName>
<contextRoot>/module4</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
<skinnyWars>true</skinnyWars>
this property make to not copy libs into war module
I have problem by running Maven-Project from command_line
I used this command in cmd to run class named mainClass
mvn -e exec:java -Dexec.mainClass="com.example.Main"
and here is what I have in my pom file:
<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>Linux</groupId>
<artifactId>Linux</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.37.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- Needs to be the same version that REST Assured depends on -->
<version>2.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
</dependencies>
</project>
I get Mojo Exception caused by class not found exception, but actually I don't know where I should provide the name or the path to the class I want to run
this is the response of the command in command-line
I have modified your Maven pom.xml and added Maven mojo plugin. You can find below the code.
First you have to build project and then you can execute the Main java class.
Here, follow the steps.
Go to command prompt and go to the project/directory containing pom.xml.
Type the command mvnw clean package. I have used maven wrapper.
Then type command mvnw exec:java -Dexec.mainClass="com.so.help.maven.Main"
You can find the sample project in github.
<?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>execute-java-maven</groupId>
<artifactId>execute-java-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<name>execute-java-maven</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.37.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- Needs to be the same version that REST Assured depends on -->
<version>2.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>com.so.help.maven.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Following
https://github.com/javafx-maven-plugin/javafx-basic-archetype
I generated a maven project using:
mvn archetype:generate -DarchetypeGroupId=com.zenjava -DarchetypeArtifactId=javafx-basic-archetype
Then, I executed mvn package from the project directory, and it generated the jar.
I tried to run the jar by double-clicking it, but nothing happens.
I tried to run via command line: java -jar Tester.jar but I get the error:
no main manifest attribute, in target\Tester.jar
Note: it does run from IntelliJIDEA if I import the project and run it, but IntelliJ doesn't generate a .jar, only .class files.
This is the pom it generates:
<?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>testgroup</groupId>
<artifactId>Tester</artifactId>
<name>Tester</name>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>testorg</name>
</organization>
<properties>
<slf4j.version>1.7.12</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<build>
<finalName>Tester</finalName>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.5</version>
<configuration>
<mainClass>testgroup.MainApp</mainClass>
<!-- only required if signing the jar file -->
<keyStoreAlias>example-user</keyStoreAlias>
<keyStorePassword>example-password</keyStorePassword>
<allPermissions>true</allPermissions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- MigLayout -->
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout-javafx</artifactId>
<version>5.0</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>
The error message basically means that you don't have path to your main class specified in Manifest.MF file.
Add to your pom.xml file the following lines of code and change mainClass argument for the proper one:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.maventest.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
After this you should run mvn clean package command and then try to run your application.
I am trying to import jersey using maven central but, intellij wont read my pom.xml dependency for jersey. The version # shows in red with the following error:
here is the pom.xml textually:
<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.example.emanuel</groupId>
<artifactId>jerseyexample</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>jerseyexample 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.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
<build>
<finalName>jerseyexample</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>TomcatServer</server>
<path>/newjersey</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
i copied the dependency straight from here
the issue was with my settings.xml file that maven uses to build the project. I had a mirror defined in there that used a proxy and it was blocking the download.
I'm new to tomcat and maven both, I created a project using IntelliJ IDEA.
there are some java classes in src directory, and the .class files is stored in target directory after building the project. It seems that tomcat cannot find where are the .class files to initialize classes.
here is the directory tree:
here is my pom.xml contetnt:
<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>IE</groupId>
<artifactId>IE</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>IE 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>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>org.json</artifactId>
<version>chargebee-1.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/javaClasses</sourceDirectory>
<finalName>IE</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<path>/projectName</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
can anybody help how can I tell the path of target file to find classes please? Now I can't instantiate any of my classes in my jsp files.
You haven't customized the configuration of the compiler plugin, therefore, it's incorrect to put your source files under src/main/javaClasses.
You should move your source packages/classes to src/main/java, and Maven should pick it up. This is where Maven expects them by default.
For more info, check standard directory layout page.