JAX-RS (Jersey) API in standalone Servlet 5 container does not start - java

Just want to build a Java application with a REST API (JAX-RS implemented by Jersey 2.33) that runs in a standalone Servlet 5 container, e.g. Tomcat 10. For this the build process (via Maven) creates a *.war file which is put subsequently into the webapps/ folder to start it.
The problem is that the JAX-RS API, that is to say its servlet, is not coming up. So calling the URL
http://localhost:8080/weld/api/address
produces HTTP Status 404 (not found).
The pom.xml looks as follows:
<?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>de.test</groupId>
<artifactId>weld</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>weld Maven Webapp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<servlet-api.version>5.0.0</servlet-api.version>
<jax-rs-api.version>2.1.6</jax-rs-api.version>
<jersey.version>2.33</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jax-rs-api.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
<build>
<finalName>weld</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
The required dependencies and the rest to get it to work I have read from the Jersey documentation.
The *.war doesn't contain any web.xml because since Servlet API 3.1 this is optional. The class javax.ws.rs.core.Application which should actually auto-detected and bootstrap the JAX-RS API looks as follows:
package de.test.weld;
import org.glassfish.jersey.server.ResourceConfig;
import javax.ws.rs.ApplicationPath;
#ApplicationPath("api")
public class MyApplication extends ResourceConfig {
public MyApplication() {
registerClasses(AddressService.class);
}
}
The Java class with the very endpoint looks then like this:
package de.test.weld;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/address")
public class AddressService {
#GET
#Produces(MediaType.APPLICATION_JSON)
public String getAddress() {
return "any text, bla, nonsense";
}
}
Anything essential seems to be missing so that the Jersey Sevlet can be started.
A glimpse into the *.war looks like this:
$> jar -tvf webapps/weld.war
0 Sat Mar 13 13:13:24 CET 2021 META-INF/
131 Sat Mar 13 13:13:22 CET 2021 META-INF/MANIFEST.MF
0 Sat Mar 13 13:13:24 CET 2021 WEB-INF/
0 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/
0 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/de/
0 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/de/test/
0 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/de/test/weld/
0 Sat Mar 13 13:13:24 CET 2021 WEB-INF/lib/
619 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/de/test/weld/AddressService.class
1025 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/de/test/weld/TestServlet.class
581 Sat Mar 13 13:13:24 CET 2021 WEB-INF/classes/de/test/weld/MyApplication.class
25058 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jakarta.annotation-api-1.3.5.jar
19479 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/osgi-resource-locator-1.0.3.jar
1174508 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jersey-common-2.33.jar
942190 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jersey-server-2.33.jar
18140 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jakarta.inject-2.6.1.jar
253811 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jersey-client-2.33.jar
91930 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jakarta.validation-api-2.0.2.jar
32383 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jersey-container-servlet-2.33.jar
73402 Fri Mar 12 15:26:10 CET 2021 WEB-INF/lib/jersey-container-servlet-core-2.33.jar
140376 Fri Mar 12 15:11:24 CET 2021 WEB-INF/lib/jakarta.ws.rs-api-2.1.6.jar
0 Sat Mar 13 13:13:24 CET 2021 META-INF/maven/
0 Sat Mar 13 13:13:24 CET 2021 META-INF/maven/de.test/
0 Sat Mar 13 13:13:24 CET 2021 META-INF/maven/de.test/weld/
2757 Sat Mar 13 13:12:34 CET 2021 META-INF/maven/de.test/weld/pom.xml
106 Sat Mar 13 13:13:24 CET 2021 META-INF/maven/de.test/weld/pom.properties
Here are some information about the versions in use:
Java 11, Maven 3.6, JAX-RS (Jersey 2.33), Servlet API 5.0.0, Tomcat 10 or Jetty 11

You need to use Jersey 3.x. The 3.x line is the first line that makes use of the Jakarta namespace. You have all the Jakarta dependencies (JAX-RS, Servlet), just the Jersey version you are using does not make use of them. See the Jersey docs for the latest 3.x version.
In the new Jakarta EE, all the javax packaging has changed to jakarta, e.g. jakarta.ws.rs.ApplicationPath. Once you change the Jersey version (assuming you don't have any other old dependencies, you should get import errors. All the javax imports should show errors. They should all be switched out with jakarta. All the javax imports (that includes JAX-RS, Servlet, Inject, etc).

Related

Cannot resolve symbol, but the dependency is in local repo

I've been reading all similar problems with maven but I cannot seem to be able to fix it. The issue is the classic "Cannot resolve symbol 'pippo'", in which case pippo is part of
import com.pippo.device.manager.data.model.Device;
This class Device comes from this artifact that I have in my local repo
<dependency>
<groupId>com.pippo</groupId>
<artifactId>device.manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Evidence that it is in the local repository
/mnt/c/Users/sanvegeta/.m2/repository$ find . -type f -name "*device.manager*" -ls
38228 -rwxrwxrwx 1 sanvegeta sanvegeta 39142700 Oct 1 09:00 ./com/pippo/device.manager/0.0.1-SNAPSHOT/device.manager-0.0.1-SNAPSHOT.jar
4 -rwxrwxrwx 1 sanvegeta sanvegeta 1969 Oct 1 08:47 ./com/pippo/device.manager/0.0.1-SNAPSHOT/device.manager-0.0.1-SNAPSHOT.pom
and evidence that this is the correct local repository
mvn help:evaluate -Dexpression=settings.localRepository | grep -v '\[INFO\]'
/mnt/c/Users/sanvegeta/.m2/repository
Just to give you a little bit of context: I'm working on a lab exercise and I created 2 microservices: com.pluto.user.manager and com.pippo.device.manager. They both expose CRUD REST API to work respectively on User and Device. Part of my exercise is to refer to the entity Device from another service (in this case from com.pluto.user.manager) so, in the user.manager, I created an API that is supposed to link the device to the user (it's just adding an id to the user, nothing serious). And the compiler complains. I even tried to create a docker container with jdk, maven and git, and tried to compile there: same problem.
The class where the error appears is the following
package com.pluto.user.manager.controller;
import com.pippo.device.manager.data.model.Device; // problem here
import com.pluto.user.manager.data.model.User;
import com.pluto.user.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
#RestController
#RequestMapping("/users")
public class UserController {
#Autowired
private UserService userService;
// various CRUD API here
// ...
#PostMapping(path = "/{id}/link", consumes = "application/json", produces = "application/json")
public User link(#PathVariable String id, #RequestBody Device device) {
return userService.linkToDevice(id, device.getId());
}
}
Please, can you help me understand what am I doing wrong?
Edit 1: adding pom.xml of user.manager as requested
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.pluto</groupId>
<artifactId>user.manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>user.manager</name>
<description>User Manager Service</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.pippo</groupId>
<artifactId>device.manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${project.parent.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
and the output of "mvn clean package"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building user.manager 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # user.manager ---
[INFO] Deleting /mnt/e/Repository/GCP/exercise1/user.manager/target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # user.manager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # user.manager ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /mnt/e/Repository/GCP/exercise1/user.manager/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /mnt/e/Repository/GCP/exercise1/user.manager/src/main/java/com/pluto/user/manager/controller/UserController.java:[3,43] package com.pippo.device.manager.data.model does not exist
[ERROR] /mnt/e/Repository/GCP/exercise1/user.manager/src/main/java/com/pluto/user/manager/controller/UserController.java:[40,99] package com.pippo.device.manager.data.model does not exist
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.983 s
[INFO] Finished at: 2021-10-01T23:01:35+02:00
[INFO] Final Memory: 28M/100M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project user.manager: Compilation failure: Compilation failure:
[ERROR] /mnt/e/Repository/GCP/exercise1/user.manager/src/main/java/com/pluto/user/manager/controller/UserController.java:[3,43] package com.pippo.device.manager.data.model does not exist
[ERROR] /mnt/e/Repository/GCP/exercise1/user.manager/src/main/java/com/pluto/user/manager/controller/UserController.java:[40,99] package com.pippo.device.manager.data.model does not exist
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
and output of jar -tvf /mnt/c/Users/sanvegeta/.m2/repository/com/pippo/device.manager/0.0.1-SNAPSHOT/device.manager-0.0.1-SNAPSHOT.jar
0 Fri Oct 01 08:59:58 CEST 2021 META-INF/
467 Fri Oct 01 08:59:58 CEST 2021 META-INF/MANIFEST.MF
0 Fri Feb 01 00:00:00 CET 1980 org/
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/
5871 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/ClassPathIndexFile.class
6806 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/ExecutableArchiveLauncher.class
3966 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/JarLauncher.class
1483 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/LaunchedURLClassLoader$DefinePackageCallType.class
1535 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.class
11154 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/LaunchedURLClassLoader.class
5932 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/Launcher.class
1536 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/MainMethodRunner.class
266 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/PropertiesLauncher$1.class
1484 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
8128 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/PropertiesLauncher$ClassPathArchives.class
1953 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
18267 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/PropertiesLauncher.class
1750 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/WarLauncher.class
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/
302 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/Archive$Entry.class
511 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/Archive$EntryFilter.class
4745 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/Archive.class
6093 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/ExplodedArchive$AbstractIterator.class
2180 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/ExplodedArchive$ArchiveIterator.class
1857 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/ExplodedArchive$EntryIterator.class
1269 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
2527 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/ExplodedArchive$SimpleJarFileArchive.class
5346 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/ExplodedArchive.class
2884 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/JarFileArchive$AbstractIterator.class
1981 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
1081 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
2528 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/JarFileArchive$NestedArchiveIterator.class
10349 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/archive/JarFileArchive.class
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/data/
485 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/data/RandomAccessData.class
282 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/data/RandomAccessDataFile$1.class
2680 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/data/RandomAccessDataFile$DataInputStream.class
3259 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/data/RandomAccessDataFile$FileAccess.class
4015 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/data/RandomAccessDataFile.class
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/
1438 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/AbstractJarFile$JarFileType.class
878 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/AbstractJarFile.class
4976 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/AsciiBytes.class
616 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/Bytes.class
295 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryEndRecord$1.class
3319 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryEndRecord$Zip64End.class
2039 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryEndRecord$Zip64Locator.class
5029 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
6889 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
4624 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryParser.class
540 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
345 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/FileHeader.class
13649 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/Handler.class
3885 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarEntry.class
1458 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarEntryCertification.class
299 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarEntryFilter.class
2299 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFile$1.class
1299 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFile$JarEntryEnumeration.class
16312 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFile.class
1368 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileEntries$1.class
2258 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
1281 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileEntries$Offsets.class
1338 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileEntries$Zip64Offsets.class
1334 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileEntries$ZipOffsets.class
17280 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileEntries.class
3512 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarFileWrapper.class
702 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarURLConnection$1.class
4302 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
9440 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/JarURLConnection.class
3559 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/StringSequence.class
1813 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jar/ZipInflaterInputStream.class
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jarmode/
293 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jarmode/JarMode.class
2201 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jarmode/JarModeLauncher.class
1292 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/jarmode/TestJarMode.class
0 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/util/
5174 Fri Feb 01 00:00:00 CET 1980 org/springframework/boot/loader/util/SystemPropertyUtils.class
0 Fri Oct 01 08:59:58 CEST 2021 BOOT-INF/
0 Fri Oct 01 08:59:58 CEST 2021 BOOT-INF/classes/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/controller/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/data/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/data/model/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/repository/
0 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/service/
0 Fri Oct 01 08:59:56 CEST 2021 META-INF/maven/
0 Fri Oct 01 08:59:56 CEST 2021 META-INF/maven/com.pippo/
0 Fri Oct 01 08:59:56 CEST 2021 META-INF/maven/com.pippo/device.manager/
804 Fri Oct 01 08:59:36 CEST 2021 BOOT-INF/classes/application.properties
737 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/Application.class
2433 Fri Oct 01 08:59:48 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/controller/DeviceController.class
1617 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/data/model/Device.class
364 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/repository/DeviceRepository.class
3530 Fri Oct 01 08:59:46 CEST 2021 BOOT-INF/classes/com/pippo/device/manager/service/DeviceService.class
1969 Fri Oct 01 08:47:32 CEST 2021 META-INF/maven/com.pippo/device.manager/pom.xml
67 Fri Oct 01 08:59:56 CEST 2021 META-INF/maven/com.pippo/device.manager/pom.properties
0 Fri Oct 01 08:59:58 CEST 2021 BOOT-INF/lib/
382204 Wed Sep 15 07:22:06 CEST 2021 BOOT-INF/lib/spring-aop-5.3.10.jar
2087074 Fri Feb 01 00:00:00 CET 1980 BOOT-INF/lib/aspectjweaver-1.9.7.jar
159222 Wed Mar 03 13:06:58 CET 2021 BOOT-INF/lib/HikariCP-4.0.3.jar
427946 Wed Sep 15 07:22:12 CEST 2021 BOOT-INF/lib/spring-jdbc-5.3.10.jar
15392 Fri Aug 02 22:14:54 CEST 2019 BOOT-INF/lib/jakarta.transaction-api-1.3.3.jar
164392 Fri Aug 02 16:59:46 CEST 2019 BOOT-INF/lib/jakarta.persistence-api-2.2.3.jar
7351256 Mon May 24 12:01:22 CEST 2021 BOOT-INF/lib/hibernate-core-5.4.32.Final.jar
60911 Tue May 25 13:11:32 CEST 2021 BOOT-INF/lib/jboss-logging-3.4.2.Final.jar
782774 Thu Mar 19 13:33:58 CET 2020 BOOT-INF/lib/javassist-3.27.0-GA.jar
3510658 Tue Mar 09 15:35:56 CET 2021 BOOT-INF/lib/byte-buddy-1.10.22.jar
445288 Wed Sep 06 11:15:04 CEST 2006 BOOT-INF/lib/antlr-2.7.7.jar
202552 Fri Jan 22 15:15:02 CET 2021 BOOT-INF/lib/jandex-2.2.3.Final.jar
67815 Sat Oct 19 22:46:30 CEST 2019 BOOT-INF/lib/classmate-1.5.1.jar
323630 Sun Apr 12 12:05:40 CEST 2020 BOOT-INF/lib/dom4j-2.1.3.jar
78948 Fri Oct 30 16:06:46 CET 2020 BOOT-INF/lib/hibernate-commons-annotations-5.1.2.Final.jar
1019255 Tue Jul 20 13:39:34 CEST 2021 BOOT-INF/lib/jaxb-runtime-2.3.5.jar
72008 Tue Jul 20 13:39:08 CEST 2021 BOOT-INF/lib/txw2-2.3.5.jar
29807 Thu Mar 18 15:25:56 CET 2021 BOOT-INF/lib/istack-commons-runtime-3.0.12.jar
68453 Thu Feb 20 18:37:08 CET 2020 BOOT-INF/lib/jakarta.activation-1.2.2.jar
375623 Fri Sep 17 09:20:56 CEST 2021 BOOT-INF/lib/spring-data-jpa-2.5.5.jar
1260499 Fri Sep 17 09:19:30 CEST 2021 BOOT-INF/lib/spring-data-commons-2.5.5.jar
204085 Wed Sep 15 07:22:22 CEST 2021 BOOT-INF/lib/spring-orm-5.3.10.jar
1267911 Wed Sep 15 07:22:10 CEST 2021 BOOT-INF/lib/spring-context-5.3.10.jar
333421 Wed Sep 15 07:22:10 CEST 2021 BOOT-INF/lib/spring-tx-5.3.10.jar
696648 Wed Sep 15 07:22:04 CEST 2021 BOOT-INF/lib/spring-beans-5.3.10.jar
41513 Tue Jul 20 13:56:20 CEST 2021 BOOT-INF/lib/slf4j-api-1.7.32.jar
47229 Wed Sep 15 07:22:24 CEST 2021 BOOT-INF/lib/spring-aspects-5.3.10.jar
1392938 Thu Sep 23 07:11:26 CEST 2021 BOOT-INF/lib/spring-boot-2.5.5.jar
1564860 Thu Sep 23 07:10:20 CEST 2021 BOOT-INF/lib/spring-boot-autoconfigure-2.5.5.jar
292027 Fri Sep 10 00:27:02 CEST 2021 BOOT-INF/lib/logback-classic-1.2.6.jar
472431 Fri Sep 10 00:15:50 CEST 2021 BOOT-INF/lib/logback-core-1.2.6.jar
17762 Sat Mar 06 22:13:24 CET 2021 BOOT-INF/lib/log4j-to-slf4j-2.14.1.jar
300365 Sat Mar 06 22:11:34 CET 2021 BOOT-INF/lib/log4j-api-2.14.1.jar
4589 Tue Jul 20 13:55:30 CEST 2021 BOOT-INF/lib/jul-to-slf4j-1.7.32.jar
25058 Fri Aug 02 11:08:52 CEST 2019 BOOT-INF/lib/jakarta.annotation-api-1.3.5.jar
326914 Mon Feb 22 05:55:56 CET 2021 BOOT-INF/lib/snakeyaml-1.28.jar
1515991 Fri Aug 27 00:33:48 CEST 2021 BOOT-INF/lib/jackson-databind-2.12.5.jar
75704 Thu Aug 26 23:31:22 CEST 2021 BOOT-INF/lib/jackson-annotations-2.12.5.jar
365536 Thu Aug 26 23:57:50 CEST 2021 BOOT-INF/lib/jackson-core-2.12.5.jar
34438 Fri Aug 27 01:10:42 CEST 2021 BOOT-INF/lib/jackson-datatype-jdk8-2.12.5.jar
120362 Fri Aug 27 01:10:24 CEST 2021 BOOT-INF/lib/jackson-datatype-jsr310-2.12.5.jar
9440 Fri Aug 27 01:10:34 CEST 2021 BOOT-INF/lib/jackson-module-parameter-names-2.12.5.jar
3429357 Mon Sep 06 23:09:00 CEST 2021 BOOT-INF/lib/tomcat-embed-core-9.0.53.jar
255802 Mon Sep 06 23:09:00 CEST 2021 BOOT-INF/lib/tomcat-embed-el-9.0.53.jar
277386 Mon Sep 06 23:09:00 CEST 2021 BOOT-INF/lib/tomcat-embed-websocket-9.0.53.jar
1633568 Wed Sep 15 07:22:16 CEST 2021 BOOT-INF/lib/spring-web-5.3.10.jar
1027620 Wed Sep 15 07:22:26 CEST 2021 BOOT-INF/lib/spring-webmvc-5.3.10.jar
288281 Wed Sep 15 07:22:04 CEST 2021 BOOT-INF/lib/spring-expression-5.3.10.jar
93107 Tue Dec 19 16:23:24 CET 2017 BOOT-INF/lib/validation-api-2.0.1.Final.jar
2303679 Mon Oct 14 09:19:50 CEST 2019 BOOT-INF/lib/h2-1.4.200.jar
115638 Mon Jan 27 09:34:38 CET 2020 BOOT-INF/lib/jakarta.xml.bind-api-2.3.3.jar
46613 Thu Feb 20 18:37:30 CET 2020 BOOT-INF/lib/jakarta.activation-api-1.2.2.jar
1479606 Fri Feb 01 00:00:00 CET 1980 BOOT-INF/lib/spring-core-5.3.10.jar
24436 Wed Sep 15 07:21:48 CEST 2021 BOOT-INF/lib/spring-jcl-5.3.10.jar
29277 Fri Feb 01 00:00:00 CET 1980 BOOT-INF/lib/spring-boot-jarmode-layertools-2.5.5.jar
2403 Fri Oct 01 09:00:00 CEST 2021 BOOT-INF/classpath.idx
212 Fri Oct 01 09:00:00 CEST 2021 BOOT-INF/layers.idx
Edit 2 (closer to the resolution)
As Stephen suggested, the internal structure of the generated jar file seems wrong. I crafted an alternative jar file with the paths that don't start with BOOT-INF/classes, and the user.manager service compiles and runs just fine.
Now the question is: how do I instruct spring boot to either generate the correct structure or to "see" the classes?
I think you have the wrong dependency. By my reading of the jar -tf output, that looks like a SpringBoot executable JAR file. The Device.class file is there, but its path is not right ... for a normal Java compiler to resolve it:
This:
BOOT-INF/classes/com/pippo/device/manager/data/model/Device.class
needs to be this:
com/pippo/device/manager/data/model/Device.class
I can't find any trace of "com.pippo.*" using Google, so I am guessing that this is a private project.
But if you want use the com.pippo.device.manager classes in other modules, you need to modify its POM file to generate a regular JAR, and use that as the dependency.
One suggestion would be to refactor the existing com.pippo / device.manager project into a SpringBoot project and a (new) regular "library" JAR project, with the former depending on the latter. Put the classes that you want to reuse in com.pluto / project.manager into the "library" project.

Maven Webjars are not found

I'm trying to use webjars for bootstrap based on their documentation
<dependencies>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
This is how I start the server.
public static void main(String[] args) throws Exception {
final Server server = createServer();
try {
server.start();
server.join();
} finally {
server.destroy();
}
}
private static Server createServer() throws Exception {
final int serverPort = getServerPort();
final Server server = new Server(serverPort);
final HandlerList servletContextHandlers = new HandlerList();
servletContextHandlers.addHandler(buildServletContextHandler());
server.setHandler(servletContextHandlers);
return server;
}
private static ServletContextHandler buildServletContextHandler() throws ConfigurationException {
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(new CustomApiBinder());
resourceConfig.packages("com.foo.api");
final ServletHolder servletHolder = new ServletHolder(new ServletContainer(resourceConfig));
final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/api");
servletContextHandler.addServlet(servletHolder, "/*");
return servletContextHandler;
}
Then when I try to link the bootstrap css sheet, I get a file not found error
<link rel='stylesheet' href='webjars/bootstrap/3.1.0/css/bootstrap.min.css'>
Do I need a special handler for that? From the documentation, it says that if you use servlet 3, you don't need anything else.
Does anyone have an example without using Spring?
Jetty 9.4.9.v20180320
Jersey 2.26
The bootstrap-<ver>.jar has a META-INF/resources/ subdirectory.
$ jar -tvf bootstrap-4.0.0.jar | grep META-INF/resources
0 Thu Jan 18 21:20:32 GMT 2018 META-INF/resources/
0 Thu Jan 18 21:20:32 GMT 2018 META-INF/resources/webjars/
0 Thu Jan 18 21:20:32 GMT 2018 META-INF/resources/webjars/bootstrap/
0 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/
0 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/
0 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/
43852 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid-jsf.css
4076 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid-jsf.css.gz
43852 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.css
4076 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.css.gz
95910 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.css.map
34243 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.min-jsf.css
3483 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.min-jsf.css.gz
34243 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.min.css
3483 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.min.css.gz
76209 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-grid.min.css.map
178152 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-jsf.css
22410 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-jsf.css.gz
4798 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot-jsf.css
1683 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot-jsf.css.gz
4798 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.css
1683 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.css.gz
57721 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.css.map
3936 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.min-jsf.css
1584 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.min-jsf.css.gz
3936 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.min.css
1584 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.min.css.gz
25881 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap-reboot.min.css.map
178152 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.css
22410 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.css.gz
411645 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.css.map
144877 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.min-jsf.css
20563 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.min-jsf.css.gz
144877 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.min.css
20563 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.min.css.gz
551641 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/css/bootstrap.min.css.map
195855 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.bundle.js
41578 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.bundle.js.gz
326634 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.bundle.js.map
67742 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.bundle.min.js
19244 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.bundle.min.js.gz
273872 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.bundle.min.js.map
115048 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.js
20137 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.js.gz
195373 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.js.map
48944 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.min.js
13105 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.min.js.gz
161998 Thu Jan 18 11:29:48 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/js/bootstrap.min.js.map
284 Thu Jan 18 21:20:32 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/webjars-requirejs.js
182 Thu Jan 18 21:20:38 GMT 2018 META-INF/resources/webjars/bootstrap/4.0.0/webjars-requirejs.js.gz
This kind of JAR is a web resource jar, and for Jetty it's only available when using a full blown WebAppContext.
Note: When using a Jetty WebAppContext all of the WEB-INF/lib/*.jar!/META-INF/resources/ contents will be unpacked into a temporary directory so that Jetty can serve the contents of those special jar files.
You have a few options from here (ordered from best/easiest choice to most complex).
Have maven unpack your META-INF/resources jars into your resources directory, that you then reference by classpath resource URL as the ServletContextHandler resource base location.
Have your own code unpack the META-INF/resources directories into a temporary directory that you then use as a the ServletContextHandler resource base directory.
Change over to using a full blown WebAppContext with a war file and all of the extra configuration necessary to enable the various features you want to use.
Note, if your eventual end goal is to build a jetty uber jar, then option 1 will be the best choice overall.
The choice you make will depend on how you eventually want to package your project up.
Will it be 1 self executing jar? Then option 1.
Will it be a collection of jars? Then options 1 and 2 are good choices.
Will it be a collection of jars and a war file? Then option 3 is a good choice.
The biggest issue with META-INF/resources based content is name collision resolution. Because of this, I encourage you to go with option 1 as this will resolve (at build time) any conflict resolution issues.
Eg: If you have 2 JAR files, both with META-INF/resources/foo.css file (but with different contents) and a request arrives for http://<host>/foo.css, which one do you serve?
For an example of Option 1 see - https://github.com/jetty-project/embedded-jetty-with-web-resources
Some embedded-jetty resources maintained by the Eclipse Jetty project:
https://www.eclipse.org/jetty/documentation/9.4.x/embedding-jetty.html
https://github.com/jetty-project/embedded-jetty-cookbook
https://github.com/eclipse/jetty.project/tree/jetty-9.4.9.v20180320/examples/embedded/
You could try to add a ResourceHandler like:
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
resourceHandler.setResourceBase(Main.class.getResource("META-INF/resources/webjars").toExternalForm());
ContextHandler webJarContext = new ContextHandler();
webJarContext.setContextPath("/webjars");
webJarContext.setHandler(resourceHandler);
As Joakim Erdfelt suggested, I use maven to copy the resources into the target classes.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-test-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>${swagger-ui.version}</version>
<type>jar</type>
<includes>META-INF/resources/webjars/**/*</includes>
<excludes>META-INF/resources/webjars/**/*index.html</excludes>
<outputDirectory>${project.basedir}/target/classes/</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven can't see installed local dependency

I have a project with following 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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I then compile and install with mvn clean install. I can see artefact installed in my .m2 dir:
lukasz#lukasz-XPS-L701X:~$ ls .m2/repository/com/example/demo/
0.0.1-SNAPSHOT maven-metadata-local.xml
I can use this file in other project when calling javac directly:
javac -cp .m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.jar
However, when I have another Maven project that has demo as dependency, Maven says it can't find it.
demo2 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>com.example</groupId>
<artifactId>demo2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When I run mvn clean compile in demo2, I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) # demo2 ---
[INFO] Deleting /home/lukasz/parent/demo2/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # demo2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # demo2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/lukasz/parent/demo2/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/lukasz/parent/demo2/src/main/java/com/example/Demo2Application.java:[11,17] cannot find symbol
symbol: class Aclass
location: class com.example.Demo2Application
[ERROR] /home/lukasz/parent/demo2/src/main/java/com/example/Demo2Application.java:[11,32] cannot find symbol
symbol: class Aclass
location: class com.example.Demo2Application
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.053 s
[INFO] Finished at: 2017-02-19T10:45:57+01:00
[INFO] Final Memory: 22M/254M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project demo2: Compilation failure: Compilation failure:
[ERROR] /home/lukasz/parent/demo2/src/main/java/com/example/Demo2Application.java:[11,17] cannot find symbol
[ERROR] symbol: class Aclass
[ERROR] location: class com.example.Demo2Application
[ERROR] /home/lukasz/parent/demo2/src/main/java/com/example/Demo2Application.java:[11,32] cannot find symbol
[ERROR] symbol: class Aclass
[ERROR] location: class com.example.Demo2Application
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
EDIT:
This is output of ls -lR .m2/repository/com/example/demo/
.m2/repository/com/example/demo/:
total 8
drwxr-xr-x 5 lukasz lukasz 4096 Feb 19 07:12 0.0.1-SNAPSHOT
-rw-r--r-- 1 lukasz lukasz 275 Feb 19 07:07 maven-metadata-local.xml
.m2/repository/com/example/demo/0.0.1-SNAPSHOT:
total 6468
drwxr-xr-x 4 lukasz lukasz 4096 Feb 19 07:07 BOOT-INF
-rw-r--r-- 1 lukasz lukasz 6595868 Feb 19 07:07 demo-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 lukasz lukasz 1410 Feb 19 01:01 demo-0.0.1-SNAPSHOT.pom
-rw-r--r-- 1 lukasz lukasz 701 Feb 19 07:07 maven-metadata-local.xml
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 META-INF
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 org
-rw-r--r-- 1 lukasz lukasz 185 Feb 19 07:07 _remote.repositories
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/BOOT-INF:
total 8
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 classes
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 lib
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/BOOT-INF/classes:
total 4
-rw-r--r-- 1 lukasz lukasz 0 Feb 19 07:07 application.properties
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 com
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/BOOT-INF/classes/com:
total 4
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 example
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/BOOT-INF/classes/com/example:
total 8
-rw-r--r-- 1 lukasz lukasz 267 Feb 19 07:07 Aclass.class
-rw-r--r-- 1 lukasz lukasz 694 Feb 19 07:07 DemoApplication.class
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/BOOT-INF/lib:
total 6384
-rw-r--r-- 1 lukasz lukasz 16521 Dec 13 18:09 jcl-over-slf4j-1.7.22.jar
-rw-r--r-- 1 lukasz lukasz 4596 Dec 13 18:09 jul-to-slf4j-1.7.22.jar
-rw-r--r-- 1 lukasz lukasz 23647 Dec 13 18:09 log4j-over-slf4j-1.7.22.jar
-rw-r--r-- 1 lukasz lukasz 305150 Jan 20 19:58 logback-classic-1.1.9.jar
-rw-r--r-- 1 lukasz lukasz 472639 Jan 20 19:57 logback-core-1.1.9.jar
-rw-r--r-- 1 lukasz lukasz 41077 Dec 13 18:07 slf4j-api-1.7.22.jar
-rw-r--r-- 1 lukasz lukasz 273599 Feb 19 2016 snakeyaml-1.17.jar
-rw-r--r-- 1 lukasz lukasz 379905 Jan 25 13:13 spring-aop-4.3.6.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 762701 Jan 25 13:13 spring-beans-4.3.6.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 662119 Jan 30 19:31 spring-boot-1.5.1.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 1038200 Jan 30 19:39 spring-boot-autoconfigure-1.5.1.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 2290 Jan 30 19:45 spring-boot-starter-1.5.1.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 2309 Jan 30 19:45 spring-boot-starter-logging-1.5.1.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 1136805 Jan 25 13:14 spring-context-4.3.6.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 1117842 Jan 25 13:13 spring-core-4.3.6.RELEASE.jar
-rw-r--r-- 1 lukasz lukasz 263304 Jan 25 13:14 spring-expression-4.3.6.RELEASE.jar
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/META-INF:
total 8
-rw-r--r-- 1 lukasz lukasz 558 Feb 19 07:07 MANIFEST.MF
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 maven
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/META-INF/maven:
total 4
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 com.example
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/META-INF/maven/com.example:
total 4
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 demo
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/META-INF/maven/com.example/demo:
total 8
-rw-r--r-- 1 lukasz lukasz 116 Feb 19 07:07 pom.properties
-rw-r--r-- 1 lukasz lukasz 1410 Feb 19 01:01 pom.xml
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org:
total 4
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 springframework
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework:
total 4
drwxr-xr-x 3 lukasz lukasz 4096 Feb 19 07:07 boot
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework/boot:
total 4
drwxr-xr-x 6 lukasz lukasz 4096 Feb 19 07:07 loader
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework/boot/loader:
total 92
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 archive
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 data
-rw-r--r-- 1 lukasz lukasz 1165 Jan 30 19:26 ExecutableArchiveLauncher$1.class
-rw-r--r-- 1 lukasz lukasz 3128 Jan 30 19:26 ExecutableArchiveLauncher.class
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 jar
-rw-r--r-- 1 lukasz lukasz 1533 Jan 30 19:26 JarLauncher.class
-rw-r--r-- 1 lukasz lukasz 2415 Jan 30 19:26 LaunchedURLClassLoader$1.class
-rw-r--r-- 1 lukasz lukasz 4698 Jan 30 19:26 LaunchedURLClassLoader.class
-rw-r--r-- 1 lukasz lukasz 4599 Jan 30 19:26 Launcher.class
-rw-r--r-- 1 lukasz lukasz 1468 Jan 30 19:26 MainMethodRunner.class
-rw-r--r-- 1 lukasz lukasz 1382 Jan 30 19:26 PropertiesLauncher$1.class
-rw-r--r-- 1 lukasz lukasz 1454 Jan 30 19:26 PropertiesLauncher$ArchiveEntryFilter.class
-rw-r--r-- 1 lukasz lukasz 16109 Jan 30 19:26 PropertiesLauncher.class
-rw-r--r-- 1 lukasz lukasz 1704 Jan 30 19:26 PropertiesLauncher$FilteredArchive$1.class
-rw-r--r-- 1 lukasz lukasz 2382 Jan 30 19:26 PropertiesLauncher$FilteredArchive.class
-rw-r--r-- 1 lukasz lukasz 1807 Jan 30 19:26 PropertiesLauncher$PrefixMatchingArchiveFilter.class
drwxr-xr-x 2 lukasz lukasz 4096 Feb 19 07:07 util
-rw-r--r-- 1 lukasz lukasz 1669 Jan 30 19:26 WarLauncher.class
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework/boot/loader/archive:
total 52
-rw-r--r-- 1 lukasz lukasz 906 Jan 30 19:26 Archive.class
-rw-r--r-- 1 lukasz lukasz 302 Jan 30 19:26 Archive$Entry.class
-rw-r--r-- 1 lukasz lukasz 399 Jan 30 19:26 Archive$EntryFilter.class
-rw-r--r-- 1 lukasz lukasz 273 Jan 30 19:26 ExplodedArchive$1.class
-rw-r--r-- 1 lukasz lukasz 4974 Jan 30 19:26 ExplodedArchive.class
-rw-r--r-- 1 lukasz lukasz 1068 Jan 30 19:26 ExplodedArchive$FileEntry.class
-rw-r--r-- 1 lukasz lukasz 3792 Jan 30 19:26 ExplodedArchive$FileEntryIterator.class
-rw-r--r-- 1 lukasz lukasz 1438 Jan 30 19:26 ExplodedArchive$FileEntryIterator$EntryComparator.class
-rw-r--r-- 1 lukasz lukasz 7016 Jan 30 19:26 JarFileArchive.class
-rw-r--r-- 1 lukasz lukasz 1749 Jan 30 19:26 JarFileArchive$EntryIterator.class
-rw-r--r-- 1 lukasz lukasz 1051 Jan 30 19:26 JarFileArchive$JarFileEntry.class
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework/boot/loader/data:
total 24
-rw-r--r-- 1 lukasz lukasz 1531 Jan 30 19:26 ByteArrayRandomAccessData.class
-rw-r--r-- 1 lukasz lukasz 551 Jan 30 19:26 RandomAccessData.class
-rw-r--r-- 1 lukasz lukasz 3390 Jan 30 19:26 RandomAccessDataFile.class
-rw-r--r-- 1 lukasz lukasz 3534 Jan 30 19:26 RandomAccessDataFile$DataInputStream.class
-rw-r--r-- 1 lukasz lukasz 2051 Jan 30 19:26 RandomAccessDataFile$FilePool.class
-rw-r--r-- 1 lukasz lukasz 1341 Jan 30 19:26 RandomAccessData$ResourceAccess.class
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework/boot/loader/jar:
total 136
-rw-r--r-- 1 lukasz lukasz 4457 Jan 30 19:26 AsciiBytes.class
-rw-r--r-- 1 lukasz lukasz 2169 Jan 30 19:26 Bytes.class
-rw-r--r-- 1 lukasz lukasz 2943 Jan 30 19:26 CentralDirectoryEndRecord.class
-rw-r--r-- 1 lukasz lukasz 5449 Jan 30 19:26 CentralDirectoryFileHeader.class
-rw-r--r-- 1 lukasz lukasz 4602 Jan 30 19:26 CentralDirectoryParser.class
-rw-r--r-- 1 lukasz lukasz 430 Jan 30 19:26 CentralDirectoryVisitor.class
-rw-r--r-- 1 lukasz lukasz 306 Jan 30 19:26 FileHeader.class
-rw-r--r-- 1 lukasz lukasz 9657 Jan 30 19:26 Handler.class
-rw-r--r-- 1 lukasz lukasz 3350 Jan 30 19:26 JarEntry.class
-rw-r--r-- 1 lukasz lukasz 262 Jan 30 19:26 JarEntryFilter.class
-rw-r--r-- 1 lukasz lukasz 2002 Jan 30 19:26 JarFile$1.class
-rw-r--r-- 1 lukasz lukasz 1199 Jan 30 19:26 JarFile$2.class
-rw-r--r-- 1 lukasz lukasz 1427 Jan 30 19:26 JarFile$3.class
-rw-r--r-- 1 lukasz lukasz 12697 Jan 30 19:26 JarFile.class
-rw-r--r-- 1 lukasz lukasz 1540 Jan 30 19:26 JarFileEntries$1.class
-rw-r--r-- 1 lukasz lukasz 10924 Jan 30 19:26 JarFileEntries.class
-rw-r--r-- 1 lukasz lukasz 1967 Jan 30 19:26 JarFileEntries$EntryIterator.class
-rw-r--r-- 1 lukasz lukasz 1300 Jan 30 19:26 JarFile$JarFileType.class
-rw-r--r-- 1 lukasz lukasz 672 Jan 30 19:26 JarURLConnection$1.class
-rw-r--r-- 1 lukasz lukasz 9111 Jan 30 19:26 JarURLConnection.class
-rw-r--r-- 1 lukasz lukasz 3641 Jan 30 19:26 JarURLConnection$JarEntryName.class
-rw-r--r-- 1 lukasz lukasz 1629 Jan 30 19:26 ZipInflaterInputStream.class
.m2/repository/com/example/demo/0.0.1-SNAPSHOT/org/springframework/boot/loader/util:
total 8
-rw-r--r-- 1 lukasz lukasz 4887 Jan 30 19:26 SystemPropertyUtils.class
Please note that I did say I can use this jar (and Aclass) when calling javac directly with -cp.
EDIT:
Source for Demo2Application.java:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Demo2Application {
public static void main(String[] args) {
SpringApplication.run(Demo2Application.class, args);
Aclass c = new Aclass();
}
}
Output of jat tvf on jar:
lukasz#lukasz-XPS-L701X:~/.m2/repository/com/example/demo/0.0.1-SNAPSHOT$ jar tvf demo-0.0.1-SNAPSHOT.jar
0 Sun Feb 19 07:07:38 CET 2017 META-INF/
558 Sun Feb 19 07:07:38 CET 2017 META-INF/MANIFEST.MF
0 Sun Feb 19 07:07:38 CET 2017 BOOT-INF/
0 Sun Feb 19 07:07:38 CET 2017 BOOT-INF/classes/
0 Sun Feb 19 07:07:34 CET 2017 BOOT-INF/classes/com/
0 Sun Feb 19 07:07:34 CET 2017 BOOT-INF/classes/com/example/
267 Sun Feb 19 07:07:34 CET 2017 BOOT-INF/classes/com/example/Aclass.class
694 Sun Feb 19 07:07:34 CET 2017 BOOT-INF/classes/com/example/DemoApplication.class
0 Sun Feb 19 07:07:30 CET 2017 BOOT-INF/classes/application.properties
0 Sun Feb 19 07:07:38 CET 2017 META-INF/maven/
0 Sun Feb 19 07:07:38 CET 2017 META-INF/maven/com.example/
0 Sun Feb 19 07:07:38 CET 2017 META-INF/maven/com.example/demo/
1410 Sun Feb 19 01:01:32 CET 2017 META-INF/maven/com.example/demo/pom.xml
116 Sun Feb 19 07:07:38 CET 2017 META-INF/maven/com.example/demo/pom.properties
0 Sun Feb 19 07:07:38 CET 2017 BOOT-INF/lib/
41077 Tue Dec 13 18:07:58 CET 2016 BOOT-INF/lib/slf4j-api-1.7.22.jar
2309 Mon Jan 30 19:45:02 CET 2017 BOOT-INF/lib/spring-boot-starter-logging-1.5.1.RELEASE.jar
2290 Mon Jan 30 19:45:02 CET 2017 BOOT-INF/lib/spring-boot-starter-1.5.1.RELEASE.jar
662119 Mon Jan 30 19:31:36 CET 2017 BOOT-INF/lib/spring-boot-1.5.1.RELEASE.jar
472639 Fri Jan 20 19:57:20 CET 2017 BOOT-INF/lib/logback-core-1.1.9.jar
4596 Tue Dec 13 18:09:14 CET 2016 BOOT-INF/lib/jul-to-slf4j-1.7.22.jar
762701 Wed Jan 25 13:13:50 CET 2017 BOOT-INF/lib/spring-beans-4.3.6.RELEASE.jar
379905 Wed Jan 25 13:13:54 CET 2017 BOOT-INF/lib/spring-aop-4.3.6.RELEASE.jar
16521 Tue Dec 13 18:09:00 CET 2016 BOOT-INF/lib/jcl-over-slf4j-1.7.22.jar
263304 Wed Jan 25 13:14:04 CET 2017 BOOT-INF/lib/spring-expression-4.3.6.RELEASE.jar
23647 Tue Dec 13 18:09:06 CET 2016 BOOT-INF/lib/log4j-over-slf4j-1.7.22.jar
1136805 Wed Jan 25 13:14:18 CET 2017 BOOT-INF/lib/spring-context-4.3.6.RELEASE.jar
1117842 Wed Jan 25 13:13:44 CET 2017 BOOT-INF/lib/spring-core-4.3.6.RELEASE.jar
1038200 Mon Jan 30 19:39:22 CET 2017 BOOT-INF/lib/spring-boot-autoconfigure-1.5.1.RELEASE.jar
305150 Fri Jan 20 19:58:16 CET 2017 BOOT-INF/lib/logback-classic-1.1.9.jar
273599 Fri Feb 19 13:13:32 CET 2016 BOOT-INF/lib/snakeyaml-1.17.jar
0 Sun Feb 19 07:07:38 CET 2017 org/
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/boot/
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/boot/loader/
2415 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/LaunchedURLClassLoader$1.class
1454 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
1807 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
4599 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/Launcher.class
1165 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/ExecutableArchiveLauncher$1.class
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/boot/loader/jar/
2002 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFile$1.class
9657 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/Handler.class
3350 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarEntry.class
1427 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFile$3.class
2943 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
430 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
1300 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFile$JarFileType.class
10924 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFileEntries.class
12697 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFile.class
1540 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFileEntries$1.class
672 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarURLConnection$1.class
1199 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFile$2.class
262 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarEntryFilter.class
4457 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/AsciiBytes.class
4602 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/CentralDirectoryParser.class
2169 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/Bytes.class
1629 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/ZipInflaterInputStream.class
1967 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
306 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/FileHeader.class
3641 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
9111 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/JarURLConnection.class
5449 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
1704 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/PropertiesLauncher$FilteredArchive$1.class
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/boot/loader/data/
1531 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/data/ByteArrayRandomAccessData.class
3534 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/data/RandomAccessDataFile$DataInputStream.class
2051 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/data/RandomAccessDataFile$FilePool.class
1341 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/data/RandomAccessData$ResourceAccess.class
3390 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/data/RandomAccessDataFile.class
551 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/data/RandomAccessData.class
4698 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/LaunchedURLClassLoader.class
1533 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/JarLauncher.class
1468 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/MainMethodRunner.class
2382 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/PropertiesLauncher$FilteredArchive.class
1382 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/PropertiesLauncher$1.class
3128 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/ExecutableArchiveLauncher.class
1669 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/WarLauncher.class
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/boot/loader/archive/
1749 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
3792 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator.class
1068 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
1051 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
302 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/Archive$Entry.class
7016 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/JarFileArchive.class
4974 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/ExplodedArchive.class
906 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/Archive.class
1438 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator$EntryComparator.class
399 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/Archive$EntryFilter.class
273 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/archive/ExplodedArchive$1.class
16109 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/PropertiesLauncher.class
0 Sun Feb 19 07:07:38 CET 2017 org/springframework/boot/loader/util/
4887 Mon Jan 30 19:26:16 CET 2017 org/springframework/boot/loader/util/SystemPropertyUtils.class
Your class is not in the jar. Or rather, it's under the BOOT-INF/classes/com/example directory instead of being under the com/example directory.
This jar file is not a jar file that can be used as a library. It's an uber jar file that has been created by the Spring-Boot plugin to contain all the dependencies and classes of your first app, along with a spring boot loader that uses a custom classloader to load the application classes and the dependencies from the uber jar.
If the jar shouldn't be a Spring boot app, but a simple library, then just don't use the Spring-Boot plugin in that project.
If it's supposed to be a library and a Spring Boot app at the same time (which is strange), then split it into two projects: one that produces a library, and a second one which is a Spring Boot app, contains just the main class of the app (and the other classes that shouldn't be in the library), and has the library as dependency.

Gradle's PMD plugin: what are acceptable arguments?

Java 1.7.0_40
Gradle 1.10
I've never used Gradle's PMD plugin and I'm running into trouble trying to add rule sets to my build.gradle. The Pmd documentation is not clear about what the valid values of ruleSets are. Their example is ruleSets = ["basic", "braces"] and they link to the "official list". There's not much to go on, unfortunately.
I was guessing the section title maps to the valid string somehow? Like,
"Basic (java)" -> "basic"
"Braces (java)" -> "braces"
But what about things like "Empty Code (java)"?
Here's a working build.gradle example:
apply plugin: 'java'
apply plugin: 'pmd'
pmd {
ruleSets = [
// The first two better work since it's right in the Javadoc...
"basic",
"braces",
// This one does not work and other variations like
// "empty code", "emptycode", "empty-code", "empty_code" do not work.
"emptyCode"
]
}
repositories {
mavenCentral()
}
Gradle spits out the following error:
$ gradle check
:pmdMain FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':pmdMain'.
> Can't find resource emptyCode. Make sure the resource is a valid file or URL
or is on the CLASSPATH. Here's the current classpath:
/Users/kuporific/gradle/gradle-1.10/lib/gradle-launcher-1.10.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
Total time: 9.907 secs
Running with --stacktrace or --debug as suggested doesn't seem to yield anything useful...
Note: create a dummy file like src/main/java/Dummy.java. Otherwise, the build will succeed.
How are ruleSets supposed to be declared?
Edit:
It ended up being easier declaring an xml rule set because it offers fine-grained control over the rules. It is included in build.gradle like so:
apply plugin: 'pmd'
pmd {
ruleSetFiles = files('path/to/ruleSet.xml')
}
And the rule set file looks something like this:
Note: This exaple is written for Gradle 1.10. Newer versions of Gradle (circa 2.0) use a newer version of PMD; therefore, many of the rulesets paths changed. So rulesets/logging-java.xml is now found in rulesets/java/logging-java.xml, for example.
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Android Application Rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd" >
<rule ref="rulesets/logging-java.xml" />
<rule ref="rulesets/basic.xml" />
<rule ref="rulesets/braces.xml" />
<rule ref="rulesets/codesize.xml" >
<exclude name="TooManyMethods" />
</rule>
<rule ref="rulesets/controversial.xml">
<exclude name="UseConcurrentHashMap" />
<exclude name="AvoidLiteralsInIfCondition" />
<exclude name="DataflowAnomalyAnalysis" />
<exclude name="CallSuperInConstructor" />
<exclude name="AtLeastOneConstructor" />
<exclude name="NullAssignment" />
</rule>
<!-- etc... -->
</ruleset>
The latest version of PMD (5.1.3 when writing this answer) is supported by gradle. The rulesets need to be prefixed by a java-
I tested this with gradle-1.12
To use PMD 5.1.3 with gradle, the following configuration defines all the possibles rulesets I could find:
pmd {
toolVersion = '5.1.3'
ruleSets = [
'java-android',
'java-basic',
'java-braces',
'java-clone',
'java-codesize',
'java-comments',
'java-controversial',
'java-coupling',
'java-design',
'java-empty',
'java-finalizers',
'java-imports',
'java-j2ee',
'java-javabeans',
'java-junit',
'java-logging-jakarta-commons',
'java-logging-java',
'java-migrating',
'java-naming',
'java-optimizations',
'java-strictexception',
'java-strings',
'java-sunsecure',
'java-typeresolution',
'java-unnecessary',
'java-unusedcode'
]
}
Reference: http://forums.gradle.org/gradle/topics/_pmdtest_fails_with_cant_find_resource_null_when_rulesets_include_braces_gradle_2_0_rc_1
I realize this is a huge edit, but it's essentially a different answer. So after speaking to you and playing around with it, I've determined that the Gradle plugin uses a slightly older version of the pmd library than is published (namely, version 4.3); however, there are a few rulesets missing from the plugin since the most recent pmd version is 5.0.5 which breaks with a NullPointerException with Gradle and Java. Now, after writing possibly the most syntactically correct and painstaking Hello World Java program of my life to test all of these, I've compiled every single Java rule-set that works with the Gradle plugin at the moment:
here's the Main.java:
package william;
import java.util.logging.Logger;
public final class Main{
private Main(){}
public static void main(final String [ ] args){
final Logger log = Logger.getLogger(Main.class.getName());
log.fine("Hello World");
}
}
here's the build.gradle:
apply plugin: 'java'
apply plugin: 'pmd'
pmd {
ruleSets = [
"basic",
"braces",
"naming",
"android",
"clone",
"codesize",
"controversial",
"design",
"finalizers",
"imports",
"j2ee",
"javabeans",
"junit",
"logging-jakarta-commons",
"logging-java",
"migrating",
"optimizations",
"strictexception",
"strings",
"sunsecure",
"typeresolution",
"unusedcode"
]
}
repositories {
mavenCentral()
}
and now you might be wondering, which rulesets AREN'T supported yet? well the answer is:
"comments"
"empty"
"unnecessary"
Trust me when I say, the rest of the rules work flawlessly. They tore me apart when writing a Hello World. So, I hope this helps, the directory that has all of the Java rulesets.xml files defined is at: link to pmd's github java ruleset directory I ignore the migrate ones, because they didn't work. I think they're for something specific.
Good luck, and I would bring up the issue of the missing rulesets on the gradle forums to petition to get them added, or update the version. Or you could custom compile the plugin and link it to the newer pmd version if you are really desperate for the missing rulesets.
To add to the other excellent answers here. After applying pmd to your gradle build and invoking it via gradle pmdMain, the pmd jar will be downloaded to your gradle cache. From there you can run:
find ~/.gradle -name "*pmd*.jar" -exec jar -tvf {} \;|grep rulesets
And you will get the output:
0 Thu Nov 10 20:48:06 EST 2011 rulesets/
0 Thu Nov 10 20:48:06 EST 2011 rulesets/internal/
0 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/
18068 Thu Nov 10 20:48:06 EST 2011 rulesets/naming.xml
65 Thu Nov 10 20:48:06 EST 2011 rulesets/jsprulesets.properties
710 Thu Nov 10 20:48:06 EST 2011 rulesets/migrating_to_15.xml
483 Thu Nov 10 20:48:06 EST 2011 rulesets/migrating_to_14.xml
1048 Thu Nov 10 20:48:06 EST 2011 rulesets/rulesets.properties
3017 Thu Nov 10 20:48:06 EST 2011 rulesets/javabeans.xml
2089 Thu Nov 10 20:48:06 EST 2011 rulesets/sunsecure.xml
777 Thu Nov 10 20:48:06 EST 2011 rulesets/migrating_to_junit4.xml
3198 Thu Nov 10 20:48:06 EST 2011 rulesets/scratchpad.xml
13190 Thu Nov 10 20:48:06 EST 2011 rulesets/strings.xml
1379 Thu Nov 10 20:48:06 EST 2011 rulesets/internal/all-java.xml
2639 Thu Nov 10 20:48:06 EST 2011 rulesets/internal/dogfood.xml
6036 Thu Nov 10 20:48:06 EST 2011 rulesets/finalizers.xml
5347 Thu Nov 10 20:48:06 EST 2011 rulesets/logging-jakarta-commons.xml
13629 Thu Nov 10 20:48:06 EST 2011 rulesets/migrating.xml
610 Thu Nov 10 20:48:06 EST 2011 rulesets/migrating_to_13.xml
3593 Thu Nov 10 20:48:06 EST 2011 rulesets/braces.xml
4163 Thu Nov 10 20:48:06 EST 2011 rulesets/clone.xml
702 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/33.xml
1332 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/41.xml
1009 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/35.xml
395 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/43.xml
1340 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/40rc1.xml
1110 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/34.xml
537 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/38.xml
346 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/37-jsp.xml
393 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/37.xml
744 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/39.xml
1066 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/36.xml
1256 Thu Nov 10 20:48:06 EST 2011 rulesets/releases/42.xml
6379 Thu Nov 10 20:48:06 EST 2011 rulesets/android.xml
4967 Thu Nov 10 20:48:06 EST 2011 rulesets/logging-java.xml
11557 Thu Nov 10 20:48:06 EST 2011 rulesets/j2ee.xml
52926 Thu Nov 10 20:48:06 EST 2011 rulesets/design.xml
9216 Thu Nov 10 20:48:06 EST 2011 rulesets/basic-jsp.xml
37773 Thu Nov 10 20:48:06 EST 2011 rulesets/basic.xml
3981 Thu Nov 10 20:48:06 EST 2011 rulesets/imports.xml
3836 Thu Nov 10 20:48:06 EST 2011 rulesets/typeresolution.xml
2755 Thu Nov 10 20:48:06 EST 2011 rulesets/unusedcode.xml
25043 Thu Nov 10 20:48:06 EST 2011 rulesets/controversial.xml
3045 Thu Nov 10 20:48:06 EST 2011 rulesets/coupling.xml
13379 Thu Nov 10 20:48:06 EST 2011 rulesets/strictexception.xml
12787 Thu Nov 10 20:48:06 EST 2011 rulesets/codesize.xml
12484 Thu Nov 10 20:48:06 EST 2011 rulesets/junit.xml
10784 Thu Nov 10 20:48:06 EST 2011 rulesets/optimizations.xml
1412 Thu Nov 10 20:48:06 EST 2011 rulesets/basic-jsf.xml
1396 Thu Nov 10 20:48:06 EST 2011 rulesets/favorites.xml
These may not all be implemented, but it is a good starting point. For a description of each file, you can check the documentation here.
When using your own rulset.xml file as described by kuporific, like:
pmd {
ruleSetFiles = files('path/to/ruleSet.xml')
}
gradle 1.10 uses some kind of default rules. Yes it does complain if the filepath is wrong, yes it complains if the contents are invalid. But during the checks some default ruleset will be applied. So I'm kind of suprised this worked for you.
Also see: http://forums.gradle.org/gradle/topics/with_gradle_1_5_pmd_applying_basic_rules_even_when_they_are_not_included_in_our_rule_set_files
Workaround is not to use ruleSetfiles, but reference them one by one:
ruleSets = [ "$projectRoot/buildtools/pmd-rules/strings.xml"]

How to to autodeploy war file with GlassFish -- from "Core JavaServerFaces" by David Geary, Cay S. Horstmann

Naive question, but this is my first step in JSF, so forgive me ;-)
I am following all the steps of the first example from "Core JavaServerFaces" by David Geary, Cay S. Horstmann (the 3rd edition).
What works in general:
java works
glassfish works
I can compile the attached code
I can create .war file
The problem begins when I copy the war file into autodeploy subdirectory of GlassFish and try to show the appropriate page in GF. In return I get 404 error and in logs I find this:
Selecting file /opt/glassfish3/glassfish/domains/domain1/autodeploy/login.war for autodeployment.
Module type not recognized for module /opt/glassfish3/glassfish/domains/domain1/applications/login
There is no installed container capable of handling this application login
Autodeploy failed : /opt/glassfish3/glassfish/domains/domain1/autodeploy/login.war.
glassfish 3.1.2, java 1.6.0_29, opensuse 11.4.
The question is how to make this code work?
Updates
jar tvf login.war
0 Thu Apr 12 22:24:24 CEST 2012 META-INF/
71 Thu Apr 12 22:24:24 CEST 2012 META-INF/MANIFEST.MF
0 Mon Jun 27 10:13:54 CEST 2011 src/
0 Mon Jun 27 10:13:54 CEST 2011 src/java/
0 Mon Jun 27 10:13:54 CEST 2011 src/java/com/
0 Thu Apr 12 22:16:32 CEST 2012 src/java/com/corejsf/
603 Thu Apr 12 22:16:32 CEST 2012 src/java/com/corejsf/UserBean.java
0 Mon Jun 27 10:13:54 CEST 2011 web/
0 Thu Apr 12 21:24:56 CEST 2012 web/WEB-INF/
877 Mon Jun 27 10:13:54 CEST 2011 web/WEB-INF/web.xml
0 Thu Apr 12 22:21:38 CEST 2012 web/WEB-INF/classes/
0 Thu Apr 12 22:21:38 CEST 2012 web/WEB-INF/classes/com/
0 Thu Apr 12 22:21:38 CEST 2012 web/WEB-INF/classes/com/corejsf/
704 Thu Apr 12 22:21:38 CEST 2012 web/WEB-INF/classes/com/corejsf/UserBean.class
0 Mon Jun 27 10:13:54 CEST 2011 web/WEB-INF/beans.xml
786 Mon Jun 27 10:13:54 CEST 2011 web/index.xhtml
394 Mon Jun 27 10:13:54 CEST 2011 web/welcome.xhtml
Your WAR file is broken.
Package it up in the web folder instead. WEB-INF should be in the root.

Categories