How to extract .war files in java? ZIP vs JAR

WAR file is just a JAR file, to extract it, just issue following jar command – jar -xvf yourWARfileName.war If the jar command is not found, which sometimes happens in the Windows command prompt, then specify full path i.e. in my case it is, c:\java\jdk-1.7.0\bin\jar -xvf my-file.war

In Maven, how output the classpath being used?

To get the classpath all by itself in a file, you can: mvn dependency:build-classpath -Dmdep.outputFile=cp.txt Or add this to the POM.XML: <project> […] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>build-classpath</id> <phase>generate-sources</phase> <goals> <goal>build-classpath</goal> </goals> <configuration> <!– configure the plugin here –> </configuration> </execution> </executions> </plugin> </plugins> </build> […] </project> From: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html This command … Read more

Appending files to a zip file with Java

In Java 7 we got Zip File System that allows adding and changing files in zip (jar, war) without manual repackaging. We can directly write to files inside zip files as in the following example. Map<String, String> env = new HashMap<>(); env.put(“create”, “true”); Path path = Paths.get(“test.zip”); URI uri = URI.create(“jar:” + path.toUri()); try (FileSystem … Read more

Maven WAR dependency

There’s another option since maven-war-plugin 2.1-alpha-2. In your WAR project: <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <attachClasses>true</attachClasses> </configuration> </plugin> This creates a classes artifact which you can use in the acceptance tests project with: <dependency> <groupId>your-group-id</groupId> <artifactId>your-artifact-id</artifactId> <version>your-version</version> <classifier>classes</classifier> </dependency>

How do I run a class in a WAR from the command line?

Similar to what Richard Detsch but with a bit easier to follow (works with packages as well) Step 1: Unwrap the War file. jar -xvf MyWar.war Step 2: move into the directory cd WEB-INF Step 3: Run your main with all dependendecies java -classpath “lib/*:classes/.” my.packages.destination.FileToRun

Advice deploying war files vs executable jar with embedded container

An interesting question. This is just my view on the topic, so take everything with a grain of salt. I have occasionally deployed and managed applications using both servlet containers and embedded servers. I’m sure there are still many good reasons for using servlet containers but I will try to just focus on why they … Read more