Why doesn't my Jsoup Maven project run? - maven

Hi I am new to Maven and JSoup and trying to run an example in Intellij so I can get an understanding of JSoup.
I added the dependencies of JSoup to my POM.xml file. I pushed to Github when the project was working. As soon as I pulled from Github the project won't run. So I went into the terminal and getting JSoup errors that certain imports don't exist. I tried to 'run' as a Maven project but now I'm even more confused.
Please see the image below which demonstrates the file structure. The code is simple its the config / setup that I am really struggling with.
Project Structure
The POM.xml content is seen below:
<?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>WebScraper</groupId>
<artifactId>WebScraper</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<!-- jsoup HTML parser library # http://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
</dependencies>
</project>
Hopefully someone can help with this.
Thanks

Related

Gradle maven publish generates invalid POM with duplicated attributes

I have a gradle multimodule project using the maven publish plugin.
The publish task fails as the maven publish plugin generates an invalid POM.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://www.w3.org/2000/xmlns/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xmlns="http://www.w3.org/2000/xmlns/">
<modelVersion xmlns="http://maven.apache.org/POM/4.0.0">4.0.0</modelVersion>
<groupId xmlns="http://maven.apache.org/POM/4.0.0">com.example</groupId>
<artifactId xmlns="http://maven.apache.org/POM/4.0.0">application</artifactId>
<version xmlns="http://maven.apache.org/POM/4.0.0">0.2.0-SNAPSHOT</version>
<packaging xmlns="http://maven.apache.org/POM/4.0.0">pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project xmlns="http://maven.apache.org/POM/4.0.0">
It clearly is invalid as there are duplicated attributes in the project starting element and the closing element has 'xmlns="http://maven.apache.org/POM/4.0.0"'
I tried gradle 5.6.0 and 6.1.1 with the same outcome.
Any idea how to fix this and what could be the cause?
I solved by applying the maven publish plugin at root project level.
When I add the code below to one of the subproject I want to publish, the generated pom is invalid:
plugins {
id 'nebula.release' version '14.0.3'
id 'maven-publish'
id 'nebula.maven-publish' version '14.1.1'
}

Create executable JAR from Groovy script

I have a maven project which consist of 1 groovy script (src/main/groovy/Main.groovy)
I am able to run it from IntelliJ by simply clicking run. What I want to do is to create an executable jar containing all dependencies so I could run in with
java -jar myjar.jar
Here's my pom:
<?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>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
</project>
I've searched on google and on so but couldn't find any working solution.
Using Maven you can set up build plugins, and one of these can be a Groovy compiler.
I wrote a blog article on setting up a Groovy compiler in Maven. But there's two parts: the groovy compiler and a plugin to package the .class files into the .jar. Traditionally for the former you'd use the groovy-eclipse-compiler and the maven-shade-plugin for the latter.
It's like 100 lines of XML in your pom file.

mac maven cannot find symbol wrong servlet-api.jar

I compile spring webflow samples project using maven in mac os and got errors. (The project compiled successfully in windows)
So I create a simple maven project to reproduce the error.
pom.xml
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
src/main/java/Test.java
import javax.servlet.ServletContext;
public class Test {
public void init(ServletContext context) {
context.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
}
}
mvn compile
The error is:
I thought is was something that maven used a wrong servlet-api.jar but not servlet as pom dependency specified which is correct. (I use javac -cp javax.servlet-api-3.0.1.jar Test.java, result no error)
I check mvn dependency:tree, the result show correct servlet-api-3.0.1.jar.
I also chech mvn script to see if there is some option to set classpath.
But I just can't figure out how maven use which jars as it's classpath.
It's very weird.
After I've imported this test maven project into eclipse,
I run mvn compile again, no error happened.

IntelliJ can't find maven dependencies for GAE

I was following along with the Creating a Simple Hello World Backend API tutorial (GAE) and all was running fine via local terminal but as soon as I opened the project in IntelliJ, IntelliJ can't build the project...
The pom file has a bunch of errors about being unable to find any dependencies, however I can still build the application just fine outside of IntelliJ.
I'm not overly familiar with Maven but I believe it is configured correctly in the IDE as I can build other generic examples generated by IntelliJ. I've attempted to re-import all dependencies but no luck...
Is there something else I need to do here?
Snippet from the pom file where both dependencies are failing to find versions.
<?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>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.helloworld</groupId>
<artifactId>helloworld</artifactId>
<properties>
<app.id>your-app-id</app.id>
<app.version>1</app.version>
<appengine.version>${appengine.version}</appengine.version>
<gcloud.plugin.version>0.9.58.v20150505</gcloud.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
</properties>
<prerequisites>
<maven>3.1.0</maven>
</prerequisites>
<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-endpoints</artifactId>
<version>${appengine.version}</version>
</dependency>
Your appengine.version property is recursively defined, so IntelliJ can't figure out what it is. Substitute <appengine.version>${appengine.version}</appengine.version> with <appengine.version>1.9.24</appengine.version> and you should be fine.

how to automatically update maven dependencies in a multi-level project?

At my workplace, different groups works on providing different services.
My team consumes these services. Currently, whenever a new version of Service is rolled out, we manually change the pom.xml to the latest version of dependency and then make a build. I am wondering if there is an automatic way of pulling latest release into build.
Here is an example to explain:
pom.xml
<?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">
<groupId>com.company.product</groupId>
<artifactId>User-Application</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<Service1-version>1.0.2</Service-1>
<Service2-version>1.1.2</Service-2>
<Service3-version>2.0.2</Service-3>
</properties>
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>Service1</artifactId>
<version>${Service1-version}</version>
</dependency>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>Service2</artifactId>
<version>${Service2-version}</version>
</dependency>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>Service3</artifactId>
<version>${Service3-version}</version>
</dependency>
.....
....
</project>
When new release of each service is made, we manually change the pom.xml to get the latest dependency. How can this be managed automatically?
The versions-maven-plugin should be able to do this with the task versions:update-properties. See an example here.

Resources