Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

How to set ImagePath in a spring boot application JAR package ? #277

Open
frankiezdh opened this issue Aug 14, 2017 · 3 comments
Open

How to set ImagePath in a spring boot application JAR package ? #277

frankiezdh opened this issue Aug 14, 2017 · 3 comments

Comments

@frankiezdh
Copy link

I wrote a spring boot application. The application is compiled and packaged into a jar. I unzip the jar, get the file structure like below.

├── META-INF
│   └── MANIFEST.MF
├── org
│   └── springframework
│       └── boot
│           └── loader
└── WEB-INF
    ├── classes
    │   ├── banner.txt
    │   ├── com
    │   │   └── xxxx
    │   │       ├── service
    │   │       │   ├── sikulix2
    │   │       │   │   └── **WechatService.class**
    │   ├── images
    │   │   ├── **1.png**
    │   │   └── **2.png**
    │   ├── logback-spring.xml
    │   ├── META-INF
    │   │   └── build-info.properties
    │   └── templates
    │       └── error.html
    └── lib

I use sikulixapi (java code below) in WechatService.class

        Screen s = new Screen();
        ImagePath.add("com.xxxx.service.sikulix2.WechatService/images");
        try {
            log.info("{}", ImagePath.get());
            log.info("{}", ImagePath.getBundlePath());
            s.click("1.png");
        } catch (FindFailed e) {
            e.printStackTrace();
        }

but i get an error while running. I read the doc faq/030-java-dev and where-sikulix-looks-for-image-files, but no help.

[error] ImagePath: add: not valid: com.xxxx.service.sikulix2.WechatService/images
2017-08-14 10:24:30.704  INFO 9140 --- [pool-2-thread-1] com.xxxx.service.sikulix2.WechatService   : {}
2017-08-14 10:24:30.708  INFO 9140 --- [pool-2-thread-1] com.xxxx.service.sikulix2.WechatService   : D:\xxxx\xxxx\xxxx
[error] Image: Image not valid, but TextSearch is switched off!
[error] RunTimeAPI: Wait: Abort: unknown
[error] RunTimeAPI: ImageMissing: 1.png
```


by the way sikulix version **1.1.2-snapshot**

@frankiezdh
Copy link
Author

I find a solution.

        Screen s = new Screen();
        try {
            ImagePath.add(new ClassPathResource("images").getURL());
            s.click("1.png");
        } catch (Exception e) {
            e.printStackTrace();
        }

@RaiMan RaiMan reopened this Sep 14, 2017
@RaiMan
Copy link
Owner

RaiMan commented Sep 14, 2017

Apparently, the class-reference-imagePath does not work in a spring application.

ImagePath.add(new ClassPathResource("images").getURL());

Is ClassPathResource Spring specific or Java standard?

@frankiezdh
Copy link
Author

@RaiMan I think iClassPathResource is specificed by Spring.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants