için iyi çalışır https://github.com/jreznot/diy-remote/blob/master/server/src/org/strangeway/diyremote/server/sys/ClasspathWebXmlConfiguration.java
İşte bunu nasıl olduğunu.
Önce, pom.xml'Bu, Webapp klasörü nerede beyan ederim: Burada
<build>
<resources>
<resource>
<directory>src/main</directory>
</resource>
</resources>
benim src/ana dizinin ağacıdır:
├── java
│ └── com
│ └── myco
│ └── myapp
│ └── worker
│ ├── App.java
| ...
├── resources
│ ├── log4j.properties
│ └── version.properties
└── webapp
├── index.html
├── index.jsp
├── lib
│ ├── inc_meta.jsp
│ └── inc_navigation.jsp
├── query.html
├── scripts
│ ├── angular.min.js
│ └── bootstrap.min.css
├── showresults.jsp
├── status.jsp
└── WEB-INF
└── web.xml
yılında Maven Gölge eklentisi ekle senin pom.xml dosyası: böyle
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>uber-${artifactId}-${version}/finalName>
</configuration>
</plugin>
Sonra
Jetty başlatın:
public static void startJetty() throws Exception {
logger.info("starting Jetty...");
Server server = new Server(8080);
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/");
/* Important: Use getResource */
String webxmlLocation = App.class.getResource("/webapp/WEB-INF/web.xml").toString();
webAppContext.setDescriptor(webxmlLocation);
/* Important: Use getResource */
String resLocation = App.class.getResource("/webapp").toString();
webAppContext.setResourceBase(resLocation);
webAppContext.setParentLoaderPriority(true);
server.setHandler(webAppContext);
server.start();
server.join();
}
Önemli olan, kavanoz içindeki dosyalara yol verecek <YourApp>.class.getResource(<your location>)
kullanmaktır. Yanlış bir şekilde bunu yapmak: Dosya sisteminde yolunu veren webContext.setDescriptor("WEB-INF/web.xml");
.
Sonra paket
$mvn clean package
uber-kavanoz dosyası oluşturulur ve kaynak olarak ilan edildi Webapp dizini içerir oluşturun.
yerde veya üretim sunucusunda kavanoz Taşı ve bunun gibi çalıştırmak
:
$ java -jar myjettyembededwithwebxmlandhtmljspfile.jar
bağlantılar kırılacak gibi görünüyor. –
Bağlantılar düzeltildi – jreznot