Martin Erlic
Martin Erlic

Reputation: 5667

Conflicts when overriding Maven dependency with local changes

I downloaded a library from Maven, but need to override a single string in one of its files so I went into the Maven Projects tab in IntelliJ and manually added the project from its pom.xml file at C:\Users\mnxe\Documents\parse4j-master\pom.xml. I can now access the .java files from within my project folder structure:

enter image description here

I did the change, by replacing API_ENDPOINT with the URL I need (FYI, https://api.parse.com no longer exists):

package org.parse4j;

public class ParseConstants {

    public static final String API_ENDPOINT = "https://parseapi.back4app.com";
    public static final String API_VERSION = "1";

    public static final String HEADER_CONTENT_TYPE = "Content-Type";
    public static final String HEADER_APPLICATION_ID = "X-Parse-Application-Id";
    public static final String HEADER_REST_API_KEY = "X-Parse-REST-API-Key";
    public static final String HEADER_MASTER_KEY = "X-Parse-Master-Key";
    public static final String HEADER_SESSION_TOKEN = "X-Parse-Session-Token";

    public static final String CONTENT_TYPE_JSON = "application/json";

    public static final String FIELD_OBJECT_ID = "objectId";
    public static final String FIELD_CREATED_AT = "createdAt";
    public static final String FIELD_UPDATED_AT = "updatedAt";
    public static final String FIELD_SESSION_TOKEN = "sessionToken";


    public static int MAX_PARSE_FILE_SIZE = 10485760;

}

My project should now work but I'm getting an exception:

3306 [main] ERROR org.parse4j.ParseObject - Request failed.
Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
    at org.json.JSONTokener.syntaxError(JSONTokener.java:433)
    at org.json.JSONObject.<init>(JSONObject.java:194)
    at org.json.JSONObject.<init>(JSONObject.java:321)
    at org.parse4j.command.ParseResponse.getJsonObject(ParseResponse.java:83)
    at org.parse4j.command.ParseResponse.getException(ParseResponse.java:71)
    at org.parse4j.ParseObject.save(ParseObject.java:492)
    at tmt.main(tmt.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

I have a feeling it's still calling the old dependency in my main pom.xml:

       <dependency>
            <groupId>com.github.thiagolocatelli</groupId>
            <artifactId>parse4j</artifactId>
            <version>1.4</version>
        </dependency>

Should I remove this dependency? If so, what is the syntax to import the new local, modified classes into my application?

Upvotes: 1

Views: 385

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35805

The following would be my suggested workflow:

  1. Go to the project where you changed the one line.
  2. Change the version in the pom.xml to something like "1.4-fixed".
  3. Call Maven (on that "stolen" project) with "clean install". Now, if you get no errors, the jar with version 1.4-fixed should be in your Local Repository (.m2/repository).
  4. Reference the version "1.4-fixed" in your old project (instead of 1.4) and build that project as well.

Of course, the version 1.4-fixed now only exists on your own machine (unless you deploy it to some company Nexus/Artifactory).

Upvotes: 1

Related Questions