I am newbie with Codenvy and I am developing a RESTful service using Jersey based on this code. When I build and run the code, the console returns this error.
[STDERR] Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jersey/api/container/grizzly/GrizzlyWebContainerFactory
[STDERR] at com.apiconnect.Main.main(Main.java:22)
[STDERR] Caused by: java.lang.ClassNotFoundException: com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory
[STDERR] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[STDERR] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[STDERR] at java.security.AccessController.doPrivileged(Native Method)
[STDERR] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[STDERR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[STDERR] ... 1 more
Line 22 is:
SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
EDIT: pom.xml is:
<?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>com.apiconnect</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>apiconnect-example</artifactId>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly</artifactId>
<version>1.9-ea01</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.9-ea01</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9-ea01</version>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<version>1.9.18-i</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.apiconnect.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>com.apiconnect.Main</mainClass>
<name>app</name>
</program>
</programs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build></project>
I have also tried my code in Netbeans and works fine. What is the problem and how can I solve it?
In Codenvy, build and run processes take place on different nodes and different environments. This project produces /repo with quite a few jars and a startup script that is impossible to inject into a Docker container (Codenvy runners are Docker based). Thus, I recommend performing build and run in the same environment, i.e. in the runtime. What you need to do is create a new runner (the button is on the runner panel), install Maven there, perform build and execute startup script. You will also have to unbind the service from localhost (see screenshot below). Your machine recipe will be the following:
FROM codenvy/jdk7
# install Maven
RUN mkdir -p /home/user/maven3 && \
wget -qO- "http://archive.apache.org/dist/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz" | tar -zx --strip-components=1 -C /home/user/maven3
ENV M2_HOME /home/user/maven3
RUN echo "export M2_HOME=$M2_HOME" >> /home/user/.bashrc
ENV PATH $M2_HOME/bin:$PATH
RUN echo "export PATH=$PATH" >> /home/user/.bashrc
#expose port
EXPOSE 9998
#map it to an external port
ENV CODENVY_APP_PORT_9998_HTTP 9998
# add project sources
ADD jax-rs-sample-1.0-SNAPSHOT-jar-with-dependencies_sources_unpack /home/user/app/
# change permissions for project folder
RUN sudo chown -R user:user /home/user/app
# build and run
CMD cd /home/user/app && \
mvn package -q && \
sudo chmod a+x /home/user/app/target/bin/app && \
/home/user/app/target/bin/app 2>&1
This will trigger a build and run the service. Take a look at the URL and port in the bottom of a runner panel. We map an exposed port in Docker to an external port on a runner instance. Hosts and ports are randomly chosen each time you hit Run.
Your code is not finding com/sun/jersey/api/container/grizzly/GrizzlyWebContainerFactory class in your classpath. Try adding below dependency:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<version>1.9.18-i</version>
</dependency>
Related
Instead of running Quarkus, I'm running OptaPlanner through a Main class entry point in Kotlin.
This works great within Intellij where I have a simple Run Configuration set up for it.
object Main {
lateinit var solverFactory: SolverFactory<VehicleRoutingSolution>
lateinit var solver: Solver<VehicleRoutingSolution>
lateinit var scoreManager: ScoreManager<VehicleRoutingSolution, SimpleLongScore>
#JvmStatic
fun main(args: Array<String>) {
...
However, when I create an Intellij artifact for a jar and try to run it, I get this:
java -jar acme.jar
Apr. 28, 2022 5:21:13 P.M. com.sun.xml.bind.v2.runtime.reflect.opt.Injector <clinit>
SEVERE: null
java.security.PrivilegedActionException: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:573)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.java:166)
at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:51)
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:157)
at com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:255)
at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:62)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:99)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:150)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:484)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:301)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:109)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1126)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:135)
at com.sun.xml.bind.v2.JAXBContextFactory.createContext(JAXBContextFactory.java:35)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:393)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:88)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:80)
at org.optaplanner.core.impl.io.jaxb.SolverConfigIO.<init>(SolverConfigIO.java:27)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlReader(SolverConfig.java:213)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:188)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:128)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:103)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:55)
at org.acme.bootstrap.Main.initOptaPlanner(Main.kt:112)
at org.acme.bootstrap.Main.main(Main.kt:43)
Caused by: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
at java.base/java.lang.Class.getMethod(Class.java:2227)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector$3.run(Injector.java:170)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector$3.run(Injector.java:166)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
... 31 more
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "com.sun.xml.bind.v2.runtime.reflect.opt.Injector.defineClass" is null
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:294)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:66)
at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:57)
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:157)
at com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:255)
at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:62)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:99)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:150)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:484)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:301)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:109)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1126)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:135)
at com.sun.xml.bind.v2.JAXBContextFactory.createContext(JAXBContextFactory.java:35)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:393)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:88)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:80)
at org.optaplanner.core.impl.io.jaxb.SolverConfigIO.<init>(SolverConfigIO.java:27)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlReader(SolverConfig.java:213)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:188)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:128)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:103)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:55)
at org.acme.bootstrap.Main.initOptaPlanner(Main.kt:112)
at org.acme.bootstrap.Main.main(Main.kt:43)
Shutting down
In solverConfig.xml I'm using <domainAccessType>REFLECTION</domainAccessType> because I cannot get Gizmo to work. I'm not sure if that's related or not, but why is there a difference between an Intellij Run Config and the Jar artifact?
Thanks
*** UPDATE ***
I still get the above error message - even when creating a very basic OptaPlanner project.
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<modelVersion>4.0.0</modelVersion>
<artifactId>foo</artifactId>
<groupId>org.acme</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Foo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.6.21</kotlin.version>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>17</kotlin.compiler.jvmTarget>
<optaplanner.version>8.20.0.Final</optaplanner.version>
</properties>
<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<build>
<finalName>foo</finalName>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.acme.bootstrap.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-bom</artifactId>
<type>pom</type>
<version>${optaplanner.version}</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
</dependency>
</dependencies>
</project>
Here's what I run with Maven:
mvn clean compile package
java -jar ./target/foo-jar-with-dependencies.jar
Note: I'm using openjdk-17.0.2
java --version
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
It still runs fine within IntelliJ's system, but from Maven it just throws the above error.
Also, here's my solverConfig.xml for reference.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<solver xmlns="https://www.optaplanner.org/xsd/solver">
<solutionClass>org.acme.domain.MySolution</solutionClass>
<entityClass>org.acme.domain.Visit</entityClass>
<scoreDirectorFactory>
<constraintProviderClass>org.acme.solver.MyConstraintProvider</constraintProviderClass>
</scoreDirectorFactory>
<termination>
<millisecondsSpentLimit>2000</millisecondsSpentLimit>
</termination>
</solver>
And my Main.kt file:
object Main {
lateinit var solverFactory: SolverFactory<MySolution>
lateinit var solver: Solver<MySolution>
lateinit var scoreManager: ScoreManager<MySolution, SimpleLongScore>
#JvmStatic
fun main(args: Array<String>) {
solverFactory = SolverFactory.createFromXmlResource("solverConfig.xml")
solver = solverFactory.buildSolver()
scoreManager = ScoreManager.create(solverFactory)
}
}
An answer to another question suggests you need an extra artifact in your project. Technically, optaplanner-core module brings it, but the scope is runtime - so that dependency may not show up in the JAR with dependencies. (?) You will need to include it yourself; you can confirm that by checking mvn dependency:tree in your project.
That said, I am not sure why we use the runtime scope here. Maybe we need to re-evaluate.
Also, seeing as you are using an uberjar, I'm going to point to another uberjar-related question to perhaps pre-empt more struggle.
I keep getting this error while trying to deploy an application to AWS:
An internal error occurred during: "Updating AWS Elastic Beanstalk environment:
SampleWebApplication".
javax/xml/bind/JAXBException
Here is what I do:
I create new Maven project based on maven-archetype-webapp 1.0
I configure the pom.xml file with dependencies (full file below)
I type in whatever to index.jsp (it's supposed to be super easy application)
I run it on tomcat7:run, it works like a charm on http://localhost:8080/
I create AWS Server
I select the project, I choose Amazon Web Services Tool --> Deploy to AWS Elastik Beanstalk, choose the added server and I keep getting this message:
I am not able to find any information about this error in the internet. The only thing that I have found is that it is connected to Java version, but I am running Java 1.8 (as was suggested in one post that I found).
Can anyone please help me? I am following this instruction for deployment of the application.
I'm super new to AWS so I don't even know where to start!
index.jsp
<html>
<body>
<h2>Hello There!</h2>
</body>
</html>
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dominikazb</groupId>
<artifactId>SampleWebApplication</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SampleWebApplication Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<tomcat.version>7.0.50</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<build>
<finalName>SampleWebApplication</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<wtpContextName>todo</wtpContextName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<verbose>true</verbose>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webappDirectory>${project.build.directory}/${project.artifactId}
</webappDirectory>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Project structure
Please, please, please help!
Finally, I find an answer to this problem in the website:
https://github.com/aws/aws-toolkit-eclipse/issues/123
The examples there were in Unix. Mine is in Window 7. What I did base on the website suggestion is:
Find where is the file jaxb-api-2.2.5.jar located. I am not sure if version 2.2.5 is a must. Suggest try whatever you have.
Mine is located in
C:\Users\myUserName\.m2\repository\javax\xml\bind\jaxb-api\2.2.5.
Exit the Eclipse IDE.
Open PowerShell in Admin mode.
cd to your user directory (my case C:\Users\myUserName) and execute the following command to open the Eclipse IDE with a -dev option which points to the jaxb-api-2.2.5.jar.
C:\Users\myUserName\eclipse\jee-2020-09\eclipse\eclipse -dev $(ls ~/.m2/repository/javax/xml/bind/jaxb-api/*/*[0-9].jar | Select-Object -Last 1)
Certainly, the location of your eclipse.exe can be different.
Happy coding!
I want to set up an automatic deployment with Gitlab CI and Docker for my Spring Boot project. For this purpose I installed Hypriot OS on my raspberry to run my docker container. The Maven and Docker build runs without errors through Gitlab CI. But if I run docker on my Raspberry, nothing happens.
gitlab-ci.yml
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
SPRING_PROFILES_ACTIVE: gitlab-ci
USER_GITLAB: ft
APP_NAME: ft-backend
REPO: backend
stages:
- build
- docker
maven-build:
image: maven:3-jdk-8
stage: build
script: "mvn package -B"
artifacts:
paths:
- target/*.jar
docker-build:
stage: docker
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker build -t registry.gitlab.com/ft/$REPO .
- docker push registry.gitlab.com/ft/$REPO
application.properties
spring.profiles.active=local
server.port=8080
spring.application.name=backend
Dockerfile
FROM jsurf/rpi-java:latest
VOLUME /tmp
ADD target/ft-backend-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
CMD [""]
I am using the following commands on my Raspberry to launch Docker. But if I want to access my Raspberry on 192...:8080, my project doesn't appear. docker ps also doesn't display anything.
docker login registry.gitlab.com
docker pull registry.gitlab.com/ft/backend
docker run -d -p 8080:8080 registry.gitlab.com/ft/backend:latest
Update
Project structure
manifest.yml
applications:
- name: hello
disk_quota: 512M
instances: 1
memory: 256M
random-route: true
timeout: 120
path: ./target/ft-backend-0.0.1-SNAPSHOT.jar
env:
JBP_CONFIG_OPEN_JDK_JRE: '[memory_calculator: {stack_threads: 100, memory_sizes: {stack: 128k, native: 150m}}]'
MANIFEST.MF
Manifest-Version: 1.0
Start-Class: hello.Application
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>de.tf</groupId>
<artifactId>ft-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</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>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>hello.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
To build a docker image of a Spring Boot maven project I recommend using dockerfile-maven-plugin.
1. Configure packaging the project as an executable jar
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
...
2. Configure building a Docker image
...
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-plugin.version}</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${docker.repository}/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
3. Create a Dockerfile
4. Build the Docker image
$ mvn clean package
See Spring Boot with Docker guide for more info.
I am trying to deploy a simple web application maven project to jboss eat 6.2 and I want to start the server and deploy the project from inside maven.
Here is my pom.xml file :
<?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.skiabox.webapps</groupId>
<artifactId>Tmt-Project2</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<jbossHome>/Users/Administrator/Servers/jboss-eap-6.2/bin</jbossHome>
<hostname>localhost</hostname>
<username>user1</username>
<password>password1</password>
<port>10001</port>
</configuration>
</plugin>
</plugins>
</build>
</project>
The error I am getting after mvm install is the following :
[ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.5.Final:run (default) on project Tmt-Project2: Modules path 'null' is not a valid directory.
It seems that maven cannot see the directory of the server that I give in the configuration tag.
I tried to reproduce your trouble: (I have got only Jboss AS 6.0 installed under Windows 7)
I copied your pom.xml to an empty directory
I removed a "/bin" from JbossHome path and used full path (starting from a drive letter)
I removed the credentials as my server instance doesn't have any configured
The server started normally after mvn clean install
So the problem may be:
JbossHome path or credentials or some your configuration files under jbossHome
It sounds like Eclipse (Kepler) does not have a proper plugin for Tomcat 8. I want to deploy my .war into Tomcat 8 and run it by Maven pom.xml file. Can anyone provide me step-by-step guidance or any resources, please?
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test-App</groupId>
<artifactId>test-rest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>test-rest Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- Tomcat plugin -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.build.finalName}</path>
<update>true</update>
<url>http:// localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcatuser</password>
</configuration>
</plugin>
</plugins>
<finalName>test-rest</finalName>
</build>
</project>
Can you use the cargo pluygin instead, this works for me, deploying to tomcat8 :
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.8</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<home>${env.CATALINA_HOME}</home>
</container>
<configuration>
<type>existing</type>
<home>${env.CATALINA_HOME}</home>
</configuration>
<deployables>
<deployable>
<groupId>com.yourcompany</groupId>
<artifactId>ROOT</artifactId>
<type>war</type>
<properties>
<context>${project.build.finalName}</context>
</properties>
</deployable>
</deployables>
<deployer>
<type>installed</type>
</deployer>
</configuration>
</plugin>
Example of how to run your war with cargo & tomcat8
mvn clean verify org.codehaus.cargo:cargo-maven2-plugin:run -Dcargo.maven.containerId=tomcat8x -Dcargo.maven.containerUrl=http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip
If you want to add it to your pom
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo.version}</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<zipUrlInstaller>
<url>http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip</url>
</zipUrlInstaller>
</container>
</configuration>
</plugin>
Then to run you war (if your pom is a war)
mvn cargo:run
To run with debug (memory options not necessary)
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo.version}</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<zipUrlInstaller>
<url>http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip</url>
</zipUrlInstaller>
</container>
<configuration>
<properties>
<!-- <cargo.servlet.port>8200</cargo.servlet.port> -->
<cargo.jvmargs>-Xmx2048m -Xms512m</cargo.jvmargs>
<cargo.start.jvmargs>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</cargo.start.jvmargs>
</properties>
</configuration>
</configuration>
</plugin>
Then you need to create a remote debug configuration in your IDE on port 8000 (port by default if nothing specified)
More commands here : https://codehaus-cargo.github.io/cargo/Maven2+plugin.html#Maven2plugin-TheCargoMavenpluginindetail
Just in case you use a separate Tomcat local server. If you use embedded tomcat, this is not applicable.
In your pom.xml, add the tomcat plugin. (You can use this for both Tomcat 7 and 8):
pom.xml
<!-- Tomcat plugin -->
<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> *(From maven > settings.xml)*
<username>*yourtomcatusername*</username>
<password>*yourtomcatpassword*</password>
</configuration>
</plugin>
tomcat-users.xml
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="password" roles="manager-gui,manager-script" />
</tomcat-users>
settings.xml (maven > conf)
<servers>
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
* deploy/re-deploy
mvn tomcat7:deploy OR
mvn tomcat7:redeploy
Tried this on (Both Ubuntu and Windows 8/10):
* Jdk 7 & Tomcat 7
* Jdk 7 & Tomcat 8
* Jdk 8 & Tomcat 7
* Jdk 8 & Tomcat 8
Tested on Both Jdk 7/8 & Tomcat 7/8. (Works with Tomcat 8.5 Also, will test Tomcat 9 soon)
Note:
Tomcat manager should be running or properly setup, before you can use it with maven.
For Tomcat 8, you should use cargo-maven2-plugin, which works for both maven 2 and maven 3. When configuration cargo plugin, make sure that the value for Container Id is "tomcat8x". Do NOT omit the "x" after tomcat8.