Categories
Java

Loading TTF-Fonts with Java

It is very easy to load some TrueType-Fonts (TTF) with Java.

1
java.awt.Font.createFont(Font.TRUETYPE_FONT, new File("font.ttf"));

But with some files I got the following Exception:

1
java.awt.FontFormatException: Font name not found

You can correct this with a font-editor to add the font names. For Linux I can advise the tool fontforge. It is very powerful also for convertions of fonts. For Debian you can simply install with the following command:

1
apt-get install fontforge
Categories
Java JBoss Maven

Get the right dependencies for JBoss 5 Client and Maven

The last days my task was to port a very complex JBoss-Application from JBoss 4.2 to 5.1.0 GA. The Application has a couple of EJBs and many logic (Stateless-Beans, Stateful-Beans, Service-MBeans, etc.), a complex Web-Application built on top of Seam 2.1 and some simple Java-Clients accessing the provided businesslogic as a JBoss Client.

The whole application is built with maven.

In the past I imported the jbossall-client.jar directly into my Maven Repository. But I thought JBoss.org provides the used JARs via the repository http://repository.jboss.org/maven2/. The right package would be:

1
2
3
4
5
<dependency>
    <groupid>org.jboss.jbossas</groupid>
    <artifactid>jboss-as-client</artifactid>
    <version>5.1.0.GA</version>
</dependency>

But this sounds better as it really is. Because of the transitive dependencies of some used packages, nearly the whole JBoss-Server is included. The developers of the JBoss-Servers sometimes using classifiers instead of splitting a mega-jar into several sub-jars. For example the org.jboss.jbossas:jboss-as-server artifact.
One solution would be to repackage all needed JARs to one JAR.
For me the solution was to build my own jboss-as-client, using a self-made pom with all needed dependencies. Because this is more the maven-way. But what is needed? This is quite easy. I tried to find the correct artifacts of the jar-files which are referenced by the jbossall-client.jar, delivered with the JBoss 5.1.0 release.

All transitive dependencies are excluded, to avoid the described problem.

If you have any suggestions how to optimize it or if I have something missed, please let me know.

And here is the result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
<dependency>
	<groupid>org.jboss.javaee</groupid>
	<artifactid>jboss-javaee</artifactid>
	<version>5.0.1.GA</version>
</dependency>
<dependency>
	<groupid>org.hibernate</groupid>
	<artifactid>hibernate-annotations</artifactid>
	<version>3.4.0.GA</version>
	<exclusions>
		<exclusion>
			<groupid>org.hibernate</groupid>
			<artifactid>hibernate-commons-annotations</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.hibernate</groupid>
			<artifactid>hibernate-core</artifactid>
		</exclusion>
		<exclusion>
			<groupid>dom4j</groupid>
			<artifactid>dom4j</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.naming</groupid>
	<artifactid>jnp-client</artifactid>
	<version>5.0.3.GA</version>
</dependency>
<dependency>
	<groupid>oswego-concurrent</groupid>
	<artifactid>concurrent</artifactid>
	<version>1.3.4-jboss-update1</version>
</dependency>
<dependency>
	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-proxy-clustered</artifactid>
	<version>1.0.1</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-proxy-impl</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-proxy-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-api</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-proxy-spi</artifactid>
	<version>1.0.0</version>
	<classifier>client</classifier>
</dependency>
<dependency>
 	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-proxy-impl</artifactid>
	<version>1.0.2</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.aspects</groupid>
			<artifactid>jboss-remoting-aspects</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-common</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-proxy-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-interceptors</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.naming</groupid>
			<artifactid>jnpserver</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
 	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-core</artifactid>
	<version>1.1.5</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>javassist</groupid>
			<artifactid>javassist</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.hibernate</groupid>
			<artifactid>hibernate</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.hibernate</groupid>
			<artifactid>hibernate-entitymanager</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-jca-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jboss-vfs</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.aop</groupid>
			<artifactid>jboss-aop</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.aop</groupid>
			<artifactid>jboss-aop-aspects</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cache</groupid>
			<artifactid>jbosscache-core</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-cache</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-endpoint</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-security</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-timerservice-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-ext-api-impl</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-proxy-clustered</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-transactions</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-ejb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jacc-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jca-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jms-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jpa</groupid>
			<artifactid>jboss-jpa-deployers</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.microcontainer</groupid>
			<artifactid>jboss-kernel</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.security</groupid>
			<artifactid>jbosssx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ws</groupid>
			<artifactid>jbossws-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>quartz</groupid>
			<artifactid>quartz</artifactid>
		</exclusion>
		<exclusion>
			<groupid>sun-jaxws</groupid>
			<artifactid>jaxws-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>sun-jaxws</groupid>
			<artifactid>jsr181-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>trove</groupid>
			<artifactid>trove</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.aspects</groupid>
			<artifactid>jboss-remoting-aspects</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-common</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-interceptors</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-proxy-impl</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-proxy-spi</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.remoting</groupid>
	<artifactid>jboss-remoting</artifactid>
	<version>2.5.1</version>
</dependency>
<dependency>
	<groupid>org.jboss.deployers</groupid>
	<artifactid>jboss-deployers-core-spi</artifactid>
	<version>2.0.7.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.deployers</groupid>
	<artifactid>jboss-deployers-core</artifactid>
	<version>2.0.7.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-main</artifactid>
	<version>5.1.0.GA</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.bootstrap</groupid>
			<artifactid>jboss-bootstrap</artifactid>
		</exclusion>
		<exclusion>
			<groupid>gnu-getopt</groupid>
			<artifactid>getopt</artifactid>
		</exclusion>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.logbridge</groupid>
			<artifactid>jboss-logbridge</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-j2se</artifactid>
	<version>5.1.0.GA</version>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-classloading-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>apache-xerces</groupid>
			<artifactid>xml-apis</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-ext-api</artifactid>
	<version>1.0.0</version>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-ejb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-server</artifactid>
	<version>5.1.0.GA</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>sun-jaxb</groupid>
			<artifactid>jaxb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-deployment</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.bootstrap</groupid>
			<artifactid>jboss-bootstrap</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-deployment-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jpa</groupid>
			<artifactid>jboss-jpa-deployers</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.security</groupid>
			<artifactid>jbosssx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-security</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-transaction-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jacc-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jms-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ws.native</groupid>
			<artifactid>jbossws-native-saaj</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ws.native</groupid>
			<artifactid>jbossws-native-jaxws</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javax.security</groupid>
			<artifactid>jaas</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jca-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>bcel</groupid>
			<artifactid>bcel</artifactid>
		</exclusion>
		<exclusion>
			<groupid>jpl-util</groupid>
			<artifactid>jpl-util</artifactid>
		</exclusion>
		<exclusion>
			<groupid>jpl-pattern</groupid>
			<artifactid>jpl-pattern</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jbossxb</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.naming</groupid>
			<artifactid>jnp-server</artifactid>
		</exclusion>
		<exclusion>
			<groupid>gnu-getopt</groupid>
			<artifactid>getopt</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-ejb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.naming</groupid>
			<artifactid>jnpserver</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-security</artifactid>
	<version>1.0.0</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.aspects</groupid>
			<artifactid>jboss-current-invocation-aspects</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-interceptors</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.security</groupid>
			<artifactid>jbosssx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jacc-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-ext-api-impl</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.aop</groupid>
			<artifactid>jboss-aop</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ejb3</groupid>
			<artifactid>jboss-ejb3-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.security</groupid>
	<artifactid>jbosssx-client</artifactid>
	<version>2.0.3.SP1</version>
</dependency>
<dependency>
	<groupid>org.jboss.deployers</groupid>
	<artifactid>jboss-deployers-client</artifactid>
	<version>2.0.7.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.deployers</groupid>
	<artifactid>jboss-deployers-client-spi</artifactid>
	<version>2.0.7.GA</version>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.man</groupid>
			<artifactid>jboss-managed</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-system-jmx</artifactid>
	<version>5.1.0.GA</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>apache-xerces</groupid>
			<artifactid>xml-apis</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jboss-vfs</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jbossxb</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.deployers</groupid>
			<artifactid>jboss-deployers-impl</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.deployers</groupid>
			<artifactid>jboss-deployers-structure-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.deployers</groupid>
			<artifactid>jboss-deployers-vfs</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.deployers</groupid>
			<artifactid>jboss-deployers-vfs-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.bootstrap</groupid>
			<artifactid>jboss-bootstrap</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.microcontainer</groupid>
			<artifactid>jboss-dependency</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.microcontainer</groupid>
			<artifactid>jboss-kernel</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.slf4j</groupid>
	<artifactid>slf4j-jboss-logging</artifactid>
	<version>1.0.2.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.logging</groupid>
	<artifactid>jboss-logging-jdk</artifactid>
	<version>2.1.0.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.logging</groupid>
	<artifactid>jboss-logging-log4j</artifactid>
	<version>2.1.0.GA</version>
	<exclusions>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.logging</groupid>
	<artifactid>jboss-logging-spi</artifactid>
	<version>2.1.0.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.ejb3</groupid>
	<artifactid>jboss-ejb3-common</artifactid>
	<version>1.0.0</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.microcontainer</groupid>
			<artifactid>jboss-kernel</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.deployers</groupid>
			<artifactid>jboss-deployers-spi</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-server</artifactid>
	<version>5.1.0.GA</version>
	<classifier>jmx-invoker-adaptor-client</classifier>
	<exclusions>
		<exclusion>
			<groupid>sun-jaxb</groupid>
			<artifactid>jabx-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-deployment</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.bootstrap</groupid>
			<artifactid>jboss-bootstrap</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-deployment-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jpa</groupid>
			<artifactid>jbopss-jpa-deployers</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.security</groupid>
			<artifactid>jbosssx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-ejb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-security</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-transaction-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jacc-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-jms-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ws.native</groupid>
			<artifactid>jbossws-native-saaj</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.ws.native</groupid>
			<artifactid>jbossws-native-jaxws</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javax.security</groupid>
			<artifactid>jaas</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jca-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>bcel</groupid>
			<artifactid>bcel</artifactid>
		</exclusion>
		<exclusion>
			<groupid>jpl-util</groupid>
			<artifactid>jpl-util</artifactid>
		</exclusion>
		<exclusion>
			<groupid>jpl-pattern</groupid>
			<artifactid>jpl-pattern</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jbossxb</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.naming</groupid>
			<artifactid>jnpserver</artifactid>
		</exclusion>
		<exclusion>
			<groupid>gnu-getopt</groupid>
			<artifactid>getopt</artifactid>
		</exclusion>
		<exclusion>
			<groupid>sun-jaxb</groupid>
			<artifactid>jaxb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jpa</groupid>
			<artifactid>jboss-jpa-deployers</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-jms-api</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-management</artifactid>
	<version>5.1.0.GA</version>
	<classifier>jsr77-client</classifier>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.deployers</groupid>
			<artifactid>jboss-deployers-vfs</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.microcontainer</groupid>
			<artifactid>jboss-kernel</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cl</groupid>
			<artifactid>jboss-classloading-vfs</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-server</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.bootstrap</groupid>
			<artifactid>jboss-bootstrap</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-connector</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-cluster</artifactid>
		</exclusion>
		<exclusion>
			<groupid>apache-xerces</groupid>
			<artifactid>xml-apis</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-iiop</artifactid>
	<version>5.1.0.GA</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>apache-avalon</groupid>
			<artifactid>avalon-framework</artifactid>
		</exclusion>
		<exclusion>
			<groupid>apache-xerces</groupid>
			<artifactid>xml-apis</artifactid>
		</exclusion>
		<exclusion>
			<groupid>jacorb</groupid>
			<artifactid>jacorb</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javax.security</groupid>
			<artifactid>jaas</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javax.transcation</groupid>
			<artifactid>jta</artifactid>
		</exclusion>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-classloading-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-corba-ots-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.integration</groupid>
			<artifactid>jboss-transaction-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.javaee</groupid>
			<artifactid>jboss-ejb-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-main</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-server</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-security</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.metadata</groupid>
			<artifactid>jboss-metadata</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javax.transaction</groupid>
			<artifactid>jta</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.cluster</groupid>
	<artifactid>jboss-ha-client</artifactid>
	<version>1.1.1.GA</version>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.aspects</groupid>
			<artifactid>jboss-remoting-aspects</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.jbossas</groupid>
	<artifactid>jboss-as-cluster</artifactid>
	<version>5.1.0.GA</version>
	<classifier>jboss-ha-legacy-client</classifier>
	<exclusions>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-server</artifactid>
		</exclusion>
		<exclusion>
			<groupid>jgroups</groupid>
			<artifactid>jgroups</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-api</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-cache-spi</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-jbc</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.cluster</groupid>
			<artifactid>jboss-ha-server-cache-jbc</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system-jmx</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.jbossas</groupid>
			<artifactid>jboss-as-system</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.bootstrap</groupid>
			<artifactid>jboss-bootstrap</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javax.transaction</groupid>
			<artifactid>jta</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.slf4j</groupid>
	<artifactid>slf4j-api</artifactid>
	<version>1.5.6</version>
</dependency>
<dependency>
	<groupid>org.jboss.aop</groupid>
	<artifactid>jboss-aop</artifactid>
	<version>2.1.1.GA</version>
	<classifier>client</classifier>
	<exclusions>
		<exclusion>
			<groupid>apache-xerces</groupid>
			<artifactid>xml-apis</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.apache.ant</groupid>
			<artifactid>ant</artifactid>
		</exclusion>
		<exclusion>
			<groupid>javassist</groupid>
			<artifactid>javassist</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jboss-reflect</artifactid>
		</exclusion>
		<exclusion>
			<groupid>qdox</groupid>
			<artifactid>qdox</artifactid>
		</exclusion>
		<exclusion>
			<groupid>trove</groupid>
			<artifactid>trove</artifactid>
		</exclusion>
		<exclusion>
			<groupid>log4j</groupid>
			<artifactid>log4j</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss</groupid>
	<artifactid>jboss-common-core</artifactid>
	<version>2.2.14.GA</version>
</dependency>
<dependency>
	<groupid>org.jboss.security</groupid>
	<artifactid>jboss-security-spi</artifactid>
	<version>2.0.3.SP1</version>
</dependency>
<dependency>
	<groupid>org.jboss</groupid>
	<artifactid>jboss-mdr</artifactid>
	<version>2.0.1.GA</version>
	<exclusions>
		<exclusion>
			<groupid>org.jboss</groupid>
			<artifactid>jboss-reflect</artifactid>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupid>org.jboss.client</groupid>
	<artifactid>jboss-client</artifactid>
	<version>5.1.0.CR1</version>
</dependency>
<dependency>
	<groupid>org.apache</groupid>
	<artifactid>xmlsec</artifactid>
	<version>1.4.2</version>
</dependency>
<dependency>
	<groupid>commons-logging</groupid>
	<artifactid>commons-logging</artifactid>
	<version>1.1.0.jboss</version>
</dependency>
<dependency>
	<groupid>org.jboss.integration</groupid>
	<artifactid>jboss-integration</artifactid>
	<version>5.1.0.GA</version>
</dependency>
<dependency>
	<groupid>jboss</groupid>
	<artifactid>jboss-serialization</artifactid>
	<version>1.0.3.GA</version>
</dependency>
<dependency>
	<groupid>org.hibernate</groupid>
	<artifactid>ejb3-persistence</artifactid>
	<version>1.0.2.GA</version>
</dependency>
<!-- andere libs -->
<dependency>
	<groupid>org.jboss.aspects</groupid>
	<artifactid>jboss-remoting-aspects</artifactid>
	<version>1.0.2</version>
	<exclusions>
		<exclusion>
			<groupid>org.jboss.aop</groupid>
			<artifactid>jboss-aop</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.microcontainer</groupid>
			<artifactid>jboss-kernel</artifactid>
		</exclusion>
		<exclusion>
			<groupid>org.jboss.security</groupid>
			<artifactid>jbosssx</artifactid>
		</exclusion>
	</exclusions>
</dependency>	
<dependency>
	<groupid>javassist</groupid>
	<artifactid>javassist</artifactid>
	<version>3.10.0.GA</version>
</dependency>
Categories
Maven

Maven: “Error installing metadata”

Today I had a problem compiling and installing a simple maven project.
Every time I ran “mvn install” I received the following error:

Error installing artifact's metadata: Error installing metadata:
Error updating group repository metadata
input contained no data

The problem here was an empty maven-metadata-local.xml in my local repository of the artifact I wanted to install. After completely removing this artifact from my repository an install was possible.

Categories
Java

Using reflection with arrays and primitive types

Sometimes it is necessary to handle a parameter of type object different for the real type. So you have to use instanceof to determine the type of an object. If you are need to check if it is an array, you can use the Reflection-API provided by the JRE. The Reflection API is a comfortable and rich functional API to inspect and manipulate Objects at runtime. One example could be to access private fields at runtime.

I had the problem to serialize some variables to JavaScript, so I wrote me a simple function:

1
public void objectToJavaScript(Object object, StringBuffer buf);

If the given object is primitive I would simple add it to the provided StringBuffer, but if it is an array I need to output ‘[‘ and ‘]’ with the given parameters. So I have to check if the object is an array:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void objectToJavaScript(Object object, StringBuffer buf) {
    if (object == null) {
        buf.append("null");
        return;
    }
    ... //other types
    if (object.getClass().isArray()) {
        buf.append('[');
        //TODO output array content
        buf.append(']');
        return;
    }
    ...
}

But how to access each entry of the array? One way could be to cast the object to Object[]. Unfortunately if the array is an array of primtive types this would throw a ClassCastException. So we have to use the functions, provided by java.lang.reflect.Array. The full code looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public void objectToJavaScript(Object object, StringBuffer buf) {
    if (object == null) {
        buf.append("null");
        return;
    }
    ... //other types
    if (object.getClass().isArray()) {
        buf.append('[');
        int len = java.lang.reflect.Array.getLength(object);
        for(int i = 0; i &lt; len; i++) {
            if (i &gt; 0) buf.append(',');
            objectToJavaScript(java.lang.reflect.Array.get(object, i), buf);
        }
        buf.append(']');
        return;
    }
    ...
}
Categories
Java

comfortable thread pools using java.util.concurrent

Today I had another time the problem to execute many short tasks in a thread pooled environment. One way could be to write the pooling itselfs (like the other times in history ;)). But I thought: Why to reinvent the wheel every time and not using standardized libraries like the java.util.concurrent.*?

What I want:

  • A self enlarging and shrinking ThreadPool depending on the queued tasks. (Because sometimes it is nothing to do and sometimes it could be to get many hundreds of tasks in a short time)
  • A definable Limit of maximum running Threads (Because we cannot create hundreds of threads just for this task. Keep in mind: the tasks have a short run time)
  • Queuing the Tasks to run later, if the ThreadPool has reached the given limits

So I looked at the given Examples and the Executors-Class, which provides fast and simple methods:

  1. newCachedThreadPool : This looks good, but unfortunately you can’t define a maximum limit of threads.
  2. newFixedThreadPool : This handles the wanted limitation, but not the automatic enlarging and shrinking.

So we cannot use the predefined methods and need to instantiate ThreadPoolExecutor directly.

Categories
Java

Java 5 – End of Service Life (EOSL)

The Standard Service Life of Java 5 expired on Friday, October 30th. This is not really tradic, because Sun provides a Java SE 6 since December 2006. But on the other side on Mac OS X (up to 10.5. Leopoard) the default JRE is Version 5.0. Standard Java Version on Mac OS X 10.5
Apple only published a Version 6 for 64 bit Intel processors. So many desktop applications still uses Java 5 as basis. It would be interessting, what Apple will do, if critical bugs in Java 5 would be found.

An overview of the whole EOL-Policy for Java can be seen at http://java.sun.com/products/archive/eol.policy.html

Categories
Java JBoss

Using TransactionAttribute in submethods on same EJB3-Beans

The EJB3 Standard provides some annotations to handle general approaches, like transactions (@TransactionAttribute) and security (@RolesAllowed, etc.). To use these methods, you only have to add them to the concerning method.

1
2
3
4
5
6
7
8
@Stateless
@Local(SampleStateless.class)
public class SampleStatelessBean implements SampleStateless {
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void sampleMethod() {
        // do some stuff
    }
}

Sometimes you have to call methods of other business objects to handle the business logic. For example you have a batch update separated into many small update steps. Here you want to split the main transaction into several small transactions and the main part should have no transaction, because it only handles the reading of external data (The example code is not complete and should only demonstrate the usage of the annotations.).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Stateless
@Local(SampleStateless.class)
public class SampleStatelessBean implements SampleStateless {
    @TransactionAttribute(TransactionAttributeType.NEVER)
    public void import() {
       //read some data
       while (haveData) {
           importData(subData);
       }
    }
 
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    private void importData(List data) {
        // do some stuff
    }
}

This above code is unfortunately NOT CORRECT. The reason is that the @TransactionAttribute-annotations will only be honored, if you call the method via a business interface. So the first solutions is to inject the bean itself and call the submethod via the injected bean.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Stateless
@Local(SampleStateless.class)
public class SampleStatelessBean implements SampleStateless {
    @EJB
    private SampleStateless bp;
 
    @TransactionAttribute(TransactionAttributeType.NEVER)
    public void import() {
       //read some data
       while (haveData) {
           bp.importData(subData);
       }
    }
 
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void importData(List data) {
        // do some stuff
    }
}

Another solution, which is quite faster on JBoss in my tests, is to use the SessionContext to get a reference to the current business object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@Stateless
@Local(SampleStateless.class)
public class SampleStatelessBean implements SampleStateless {
    private SampleStateless bp;
 
    @Resource
    private SessionContext ctx;
 
    @PostConstruct
    public void init() {
        bp = ctx.getBusinessObject(SampleStateless.class);
    }
 
    @TransactionAttribute(TransactionAttributeType.NEVER)
    public void import() {
       //read some data
       while (haveData) {
           bp.importData(subData);
       }
    }
 
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void importData(List data) {
        // do some stuff
    }
}
Categories
Java

Reading JPEGs with CMYK profile

Today I tried to read a JPEG with the ImageIO-Library, provided by the JRE. But instead of a wonderful image I only received the following exception:

1
2
3
4
5
6
7
8
java.lang.IllegalArgumentException: bandOffsets.length is wrong!
	at javax.imageio.ImageTypeSpecifier$Interleaved.< init >(ImageTypeSpecifier.java:382)
	at javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:495)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageTypes(JPEGImageReader.java:743)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:935)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:912)
	at javax.imageio.ImageIO.read(ImageIO.java:1400)
	at javax.imageio.ImageIO.read(ImageIO.java:1322)

With an EXIF-Reader (by the way a nice website) I tried to analyze the picture and saw the picture includes an embedded color profile “(unrecognized embedded color profile ‘SWOP (Coated), 20%’)”. A little bit more research showed the currently unresolved bugs in the JRE (especially ImageIO-Library; #4799903 and #5100094). So I’m not the only person, who had the problem. There are some code snippets and bug workarounds on the net trying to convert CMYK or YCCK to RGB. For my picture the CMYK-Solution doesn’t work, because the JRE means the embedded ICC profile doesn’t match the given raster (raster contains 3 bytes per pixel, but CMYK 4 bytes). But Werner Randelshofer wrote that it is important to use the given ICC, because of unexpectable color problems. So just to use a fix conversion method is not the wanted solution.

Then I tried first not to use the ImageIO library, but to give AWT-Toolkit a try. I was very surprised, that this function can correctly read the given image. So I didn’t need to handle the embedded ICC profiles directly. I modified my code to use this method, if ImageIO fails. The resulting code looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    private BufferedImage readImage(InputStream picture) throws IOException {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        byte[] b = new byte[10240];
        int l = 0;
        while ((l = picture.read(b)) >= 0) {
            buf.write(b, 0, l);
        }
        buf.close();
        byte[] picturedata = buf.toByteArray();
        buf = null;
        try {
            return ImageIO.read(new ByteArrayInputStream(picturedata));
        } catch (IllegalArgumentException e) {
                ImageInputStream input = ImageIO
                        .createImageInputStream(new ByteArrayInputStream(
                                picturedata));
                Iterator< ImageReader > readers = ImageIO.getImageReaders(input);
                ImageReader reader = null;
                while (readers.hasNext()) {
                    reader = (ImageReader) readers.next();
                    if (reader.canReadRaster())
                        break;
                }
 
                if (reader == null)
                    throw new IOException("no reader found");
                // Set the input.
                reader.setInput(input);
                int w = reader.getWidth(0);
                int h = reader.getHeight(0);
                BufferedImage image;
                image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
                Image intImage = Toolkit.getDefaultToolkit().createImage(
                        picturedata);
                new ImageIcon(intImage);
                Graphics2D g = image.createGraphics();
                g.drawImage(intImage, 0, 0, null);
                g.dispose();
                return image;
        }
    }

The Toolkit-Method also has no problems on servers without an X11 server.

Categories
Maven

Running classes via maven from console

If you use maven to compile and handle your applications, you may want to directly call it from console. Here you can use the Maven-Exec-Plugin. This plugin provides an easy method to execute Java-Classes. Of course you can configure the plugin as usual in you pom.xml, but you also can directly use it from the console.

To run a simple class you can use:

1
mvn exec:java -Dexec.mainClass=info.javahelp.examples.Example

The advantage is that java is correctly called with all used jar-dependencies and the resulting classpath.

To affect the used dependencies you can also define the used scope (default: compile). For example your application is in testing scope you can run it with:

1
mvn exec:java -Dexec.mainClass=info.javahelp.examples.tests.Example -Dexec.classpathScope=test
Categories
Java

Drawing aliased lines with Java

Java provides a very flexible API for drawing images. This API also support aliased drawing of lines, text, etc. To activate it, you have to set the RenderingHints of the Graphics-Object (line 3). After that all operations results in aliased objects. To draw half pixels, you can use g.scale or g.translate with double-values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
        BufferedImage image = new BufferedImage(200,200,BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(Color.white);
        g.fillRect(0, 0, 199, 199);
        g.setColor(Color.black);
        double step = 2.5;
        g.scale(step, 1);
        for (int i = 0; i &lt; (int)(200/step); i++) {
            if (i % 2 == 1) {
                g.fillRect(0, 0, 1, 199);
            }
            g.translate(1, 0);
        }
        ImageIO.write(image, "png", new File("test.png"));