Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'could not find or load ${start-class}' when trying this with spring boot pet clinic #170

Closed
patflynn opened this issue Mar 14, 2018 · 6 comments

Comments

@patflynn
Copy link
Contributor

patflynn commented Mar 14, 2018

to reproduce:
try out:
$ git clone https://github.com/spring-projects/spring-petclinic.git
$ cd spring-petclinic
$ ./mvnw spring-boot:run

modify pom.xml to include

       <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>jib-maven-plugin</artifactId>
            <version>0.1.4</version>
            <configuration>
                <registry>gcr.io</registry>
                <repository>your project/app/repository>
            </configuration>
        </plugin>

mvnw compile jib:build
docker pull and run

see:
'could not find or load ${start-class}'

@coollog
Copy link
Contributor

coollog commented Mar 14, 2018

I believe this is due to there not being a default main class provided (the spring-petclinic doesn't seem to package an executable JAR and thus, we don't find a Main-Class attribute in the maven-jar-plugin). Therefore, Spring may be setting ${start-class} as the main class for maven-jar-plugin, but since start-class is not defined, it doesn't get resolved. I tried adding <start-class>org.springframework.samples.petclinic.PetClinicApplication</start-class> in the pom.xml properties and it seems to have worked.

Alternatively, one could explicitly pass in the main class to the jib-maven-plugin configuration.

@patflynn
Copy link
Contributor Author

patflynn commented Mar 14, 2018 via email

@coollog
Copy link
Contributor

coollog commented Mar 14, 2018

  1. For this, we could either check if the main class we detect is a valid Java class qualifier (something like ([a-z]+\.?)+), or check explicitly for any ${...} in it (indicating some unresolved Maven property).

  2. From https://spring.io/guides/gs/spring-boot/, It looks like Spring Boot Maven plugin searches for the class to run as the main class by looking for a class with public static void main(), although it seems that defining a start-class property is the recommended way (https://www.mkyong.com/spring-boot/spring-boot-which-main-class-to-start/, https://stackoverflow.com/questions/23217002/how-do-i-tell-spring-boot-which-main-class-to-use-for-the-executable-jar/31040641). We could potentially also try looking for a class with public static void main() and use that as the default main class.

@loosebazooka
Copy link
Member

So 2 would look for a single main class? and fail if multiple are found?

@coollog
Copy link
Contributor

coollog commented Mar 22, 2018

@loosebazooka Yes

@coollog
Copy link
Contributor

coollog commented Mar 22, 2018

There is still the problem of when to do the main method search.

If we do the search after inferring from the jar plugin, this issue still happens since Spring boot is actually setting the jar plugin's main class to ${start-class}.

If we do the search before the jar plugin, we may have the user experience a difference between running their jar and running the jibbed image.

We might still need logic to detect if the main class is a valid java class.

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

No branches or pull requests

3 participants