Skip to content

Commit 1455bc0

Browse files
committed
Add a Maven project
1 parent 7d9b828 commit 1455bc0

6 files changed

Lines changed: 1310 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Build script for LiteCam Barcode Scanner Maven Example
2+
# PowerShell version
3+
4+
$ErrorActionPreference = "Stop"
5+
6+
# Define Maven executable path
7+
$MavenPath = "C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.11\bin\mvn.cmd"
8+
9+
Write-Host "Building LiteCam Barcode Scanner Maven Example..." -ForegroundColor Green
10+
Write-Host "=================================================" -ForegroundColor Green
11+
12+
# Check if Maven is available at the expected path
13+
if (-not (Test-Path $MavenPath)) {
14+
# Try to find Maven in PATH
15+
if (-not (Get-Command mvn -ErrorAction SilentlyContinue)) {
16+
Write-Host "Error: Maven is not installed or not found" -ForegroundColor Red
17+
Write-Host "Expected Maven location: $MavenPath" -ForegroundColor Red
18+
exit 1
19+
} else {
20+
$MavenPath = "mvn"
21+
}
22+
}
23+
24+
# Check if Java is installed
25+
if (-not (Get-Command java -ErrorAction SilentlyContinue)) {
26+
Write-Host "Error: Java is not installed or not in PATH" -ForegroundColor Red
27+
exit 1
28+
}
29+
30+
# Verify litecam.jar exists
31+
if (-not (Test-Path "libs\litecam.jar")) {
32+
Write-Host "Error: litecam.jar not found in libs\ directory" -ForegroundColor Red
33+
Write-Host "Please copy litecam.jar to libs\ directory first" -ForegroundColor Red
34+
exit 1
35+
}
36+
37+
Write-Host "`nJava version:" -ForegroundColor Yellow
38+
java -version
39+
40+
Write-Host "`nMaven version:" -ForegroundColor Yellow
41+
& $MavenPath -version
42+
43+
Write-Host "`nCleaning previous build..." -ForegroundColor Yellow
44+
& $MavenPath clean
45+
46+
Write-Host "`nCompiling project..." -ForegroundColor Yellow
47+
& $MavenPath compile
48+
49+
Write-Host "`nRunning tests..." -ForegroundColor Yellow
50+
& $MavenPath test
51+
52+
Write-Host "`nCreating fat JAR with dependencies..." -ForegroundColor Yellow
53+
& $MavenPath package
54+
55+
Write-Host "`nBuild completed successfully!" -ForegroundColor Green
56+
Write-Host ""
57+
Write-Host "To run the application:"
58+
Write-Host " Option 1: & `"$MavenPath`" exec:java -Dexec.mainClass=`"com.example.litecam.BarcodeScanner`""
59+
Write-Host " Option 2: java -jar target\litecam-barcode-scanner-1.0-SNAPSHOT-shaded.jar"
60+
Write-Host ""
61+
62+
$jarPath = "target\litecam-barcode-scanner-1.0-SNAPSHOT-shaded.jar"
63+
if (Test-Path $jarPath) {
64+
$jarSize = (Get-Item $jarPath).Length
65+
$jarSizeMB = [math]::Round($jarSize / 1MB, 2)
66+
Write-Host "JAR file created: $jarPath"
67+
Write-Host "JAR size: $jarSizeMB MB"
68+
} else {
69+
Write-Host "Warning: JAR file not found at expected location" -ForegroundColor Yellow
70+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
# Build script for LiteCam Barcode Scanner Maven Example
3+
4+
set -e
5+
6+
echo "Building LiteCam Barcode Scanner Maven Example..."
7+
echo "================================================="
8+
9+
# Check if Maven is installed
10+
if ! command -v mvn &> /dev/null; then
11+
echo "Error: Maven is not installed or not in PATH"
12+
exit 1
13+
fi
14+
15+
# Check if Java is installed
16+
if ! command -v java &> /dev/null; then
17+
echo "Error: Java is not installed or not in PATH"
18+
exit 1
19+
fi
20+
21+
# Verify litecam.jar exists
22+
if [ ! -f "libs/litecam.jar" ]; then
23+
echo "Error: litecam.jar not found in libs/ directory"
24+
echo "Please copy litecam.jar to libs/ directory first"
25+
exit 1
26+
fi
27+
28+
echo "Java version:"
29+
java -version
30+
31+
echo ""
32+
echo "Maven version:"
33+
mvn -version
34+
35+
echo ""
36+
echo "Cleaning previous build..."
37+
mvn clean
38+
39+
echo ""
40+
echo "Compiling project..."
41+
mvn compile
42+
43+
echo ""
44+
echo "Running tests..."
45+
mvn test
46+
47+
echo ""
48+
echo "Creating fat JAR with dependencies..."
49+
mvn package
50+
51+
echo ""
52+
echo "Build completed successfully!"
53+
echo ""
54+
echo "To run the application:"
55+
echo " Option 1: mvn exec:java -Dexec.mainClass=\"com.example.litecam.BarcodeScanner\""
56+
echo " Option 2: java -jar target/litecam-barcode-scanner-1.0-SNAPSHOT-shaded.jar"
57+
echo ""
58+
echo "JAR file created: target/litecam-barcode-scanner-1.0-SNAPSHOT-shaded.jar"
59+
echo "JAR size: $(du -h target/litecam-barcode-scanner-1.0-SNAPSHOT-shaded.jar 2>/dev/null | cut -f1 || echo 'Unknown')"
127 KB
Binary file not shown.
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.example</groupId>
9+
<artifactId>litecam-barcode-scanner</artifactId>
10+
<version>1.0.0</version>
11+
<packaging>jar</packaging>
12+
13+
<name>LiteCam Barcode Scanner</name>
14+
<description>A barcode scanning application using LiteCam SDK with Dynamsoft DBR and ZXing</description>
15+
16+
<properties>
17+
<maven.compiler.source>11</maven.compiler.source>
18+
<maven.compiler.target>11</maven.compiler.target>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<java.version>11</java.version>
21+
22+
<!-- Dependency versions -->
23+
<dynamsoft.dbr.version>11.0.6100</dynamsoft.dbr.version>
24+
<zxing.version>3.5.3</zxing.version>
25+
<slf4j.version>2.0.9</slf4j.version>
26+
<logback.version>1.4.11</logback.version>
27+
<junit.version>5.10.0</junit.version>
28+
</properties>
29+
30+
<repositories>
31+
<repository>
32+
<id>central</id>
33+
<url>https://repo1.maven.org/maven2</url>
34+
</repository>
35+
<repository>
36+
<id>dbr</id>
37+
<url>https://download2.dynamsoft.com/maven/dbr/jar</url>
38+
</repository>
39+
</repositories>
40+
41+
<dependencies>
42+
<!-- LiteCam SDK (local JAR installed to local repository) -->
43+
<dependency>
44+
<groupId>com.example</groupId>
45+
<artifactId>litecam</artifactId>
46+
<version>1.0.0</version>
47+
</dependency>
48+
49+
<!-- Dynamsoft Barcode Reader -->
50+
<dependency>
51+
<groupId>com.dynamsoft</groupId>
52+
<artifactId>dbr</artifactId>
53+
<version>${dynamsoft.dbr.version}</version>
54+
</dependency>
55+
56+
<!-- ZXing Core for barcode processing -->
57+
<dependency>
58+
<groupId>com.google.zxing</groupId>
59+
<artifactId>core</artifactId>
60+
<version>${zxing.version}</version>
61+
</dependency>
62+
63+
<!-- ZXing JavaSE for BufferedImage support -->
64+
<dependency>
65+
<groupId>com.google.zxing</groupId>
66+
<artifactId>javase</artifactId>
67+
<version>${zxing.version}</version>
68+
</dependency>
69+
70+
<!-- Additional ZXing support for various barcode formats -->
71+
<dependency>
72+
<groupId>com.google.zxing</groupId>
73+
<artifactId>zxing-parent</artifactId>
74+
<version>${zxing.version}</version>
75+
<type>pom</type>
76+
</dependency>
77+
78+
<!-- Logging -->
79+
<dependency>
80+
<groupId>org.slf4j</groupId>
81+
<artifactId>slf4j-api</artifactId>
82+
<version>${slf4j.version}</version>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>ch.qos.logback</groupId>
87+
<artifactId>logback-classic</artifactId>
88+
<version>${logback.version}</version>
89+
</dependency>
90+
91+
<!-- JSON processing for configuration and results -->
92+
<dependency>
93+
<groupId>com.fasterxml.jackson.core</groupId>
94+
<artifactId>jackson-databind</artifactId>
95+
<version>2.15.2</version>
96+
</dependency>
97+
98+
<!-- Apache Commons for utilities -->
99+
<dependency>
100+
<groupId>org.apache.commons</groupId>
101+
<artifactId>commons-lang3</artifactId>
102+
<version>3.13.0</version>
103+
</dependency>
104+
105+
<!-- Test dependencies -->
106+
<dependency>
107+
<groupId>org.junit.jupiter</groupId>
108+
<artifactId>junit-jupiter</artifactId>
109+
<version>${junit.version}</version>
110+
<scope>test</scope>
111+
</dependency>
112+
</dependencies>
113+
114+
<build>
115+
<plugins>
116+
<!-- Maven Compiler Plugin -->
117+
<plugin>
118+
<groupId>org.apache.maven.plugins</groupId>
119+
<artifactId>maven-compiler-plugin</artifactId>
120+
<version>3.11.0</version>
121+
<configuration>
122+
<source>${java.version}</source>
123+
<target>${java.version}</target>
124+
<encoding>${project.build.sourceEncoding}</encoding>
125+
</configuration>
126+
</plugin>
127+
128+
<!-- Maven Surefire Plugin for running tests -->
129+
<plugin>
130+
<groupId>org.apache.maven.plugins</groupId>
131+
<artifactId>maven-surefire-plugin</artifactId>
132+
<version>3.1.2</version>
133+
<configuration>
134+
<includes>
135+
<include>**/*Test.java</include>
136+
<include>**/*Tests.java</include>
137+
</includes>
138+
</configuration>
139+
</plugin>
140+
141+
<!-- Maven Shade Plugin for creating fat JAR -->
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-shade-plugin</artifactId>
145+
<version>3.5.0</version>
146+
<executions>
147+
<execution>
148+
<phase>package</phase>
149+
<goals>
150+
<goal>shade</goal>
151+
</goals>
152+
<configuration>
153+
<transformers>
154+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
155+
<mainClass>com.example.litecam.BarcodeScanner</mainClass>
156+
</transformer>
157+
</transformers>
158+
<filters>
159+
<filter>
160+
<artifact>*:*</artifact>
161+
<excludes>
162+
<exclude>META-INF/*.SF</exclude>
163+
<exclude>META-INF/*.DSA</exclude>
164+
<exclude>META-INF/*.RSA</exclude>
165+
</excludes>
166+
</filter>
167+
</filters>
168+
<!-- Force inclusion of system dependencies -->
169+
<artifactSet>
170+
<includes>
171+
<include>*:*</include>
172+
</includes>
173+
</artifactSet>
174+
</configuration>
175+
</execution>
176+
</executions>
177+
</plugin>
178+
179+
<!-- Maven Resources Plugin -->
180+
<plugin>
181+
<groupId>org.apache.maven.plugins</groupId>
182+
<artifactId>maven-resources-plugin</artifactId>
183+
<version>3.3.1</version>
184+
<configuration>
185+
<encoding>${project.build.sourceEncoding}</encoding>
186+
</configuration>
187+
</plugin>
188+
189+
<!-- Copy LiteCam JAR to libs directory during validate phase -->
190+
<plugin>
191+
<groupId>org.apache.maven.plugins</groupId>
192+
<artifactId>maven-antrun-plugin</artifactId>
193+
<version>3.1.0</version>
194+
<executions>
195+
<execution>
196+
<id>copy-litecam-jar</id>
197+
<phase>validate</phase>
198+
<goals>
199+
<goal>run</goal>
200+
</goals>
201+
<configuration>
202+
<target>
203+
<copy file="${project.basedir}/../litecam.jar"
204+
todir="${project.basedir}/libs"
205+
failonerror="false"/>
206+
</target>
207+
</configuration>
208+
</execution>
209+
</executions>
210+
</plugin>
211+
212+
<!-- Install LiteCam JAR to local Maven repository -->
213+
<plugin>
214+
<groupId>org.apache.maven.plugins</groupId>
215+
<artifactId>maven-install-plugin</artifactId>
216+
<version>3.1.1</version>
217+
<executions>
218+
<execution>
219+
<id>install-litecam</id>
220+
<phase>initialize</phase>
221+
<goals>
222+
<goal>install-file</goal>
223+
</goals>
224+
<configuration>
225+
<file>${project.basedir}/libs/litecam.jar</file>
226+
<groupId>com.example</groupId>
227+
<artifactId>litecam</artifactId>
228+
<version>1.0.0</version>
229+
<packaging>jar</packaging>
230+
</configuration>
231+
</execution>
232+
</executions>
233+
</plugin>
234+
</plugins>
235+
</build>
236+
237+
<profiles>
238+
<!-- Development profile -->
239+
<profile>
240+
<id>dev</id>
241+
<activation>
242+
<activeByDefault>true</activeByDefault>
243+
</activation>
244+
<properties>
245+
<log.level>DEBUG</log.level>
246+
</properties>
247+
</profile>
248+
249+
<!-- Production profile -->
250+
<profile>
251+
<id>prod</id>
252+
<properties>
253+
<log.level>INFO</log.level>
254+
</properties>
255+
</profile>
256+
</profiles>
257+
</project>

0 commit comments

Comments
 (0)